                     return TransactionStore.shared.clear()
                 }
                 _ = TransactionStore.shared.resume(callbackURL, options: [:])
-                }
-            self.authSession = authSession
-            authSession.start()
+            })
         } else {
-            let authSession = SFAuthenticationSession(url: authorizeURL, callbackURLScheme: self.redirectURL.absoluteString) { [unowned self] in
+            authSession = .init(SFAuthenticationSession(url: authorizeURL, callbackURLScheme: self.redirectURL.absoluteString) { [unowned self] in
                 guard $1 == nil, let callbackURL = $0 else {
                     let authError = $1 ?? WebAuthError.unknownError
                     if case SFAuthenticationError.canceledLogin = authError {

#if swift(>=3.2)
@available(iOS 11.0, *)
class SafariAuthenticationSession: AuthSession {

    private var authSession: NSObject?

    init(authorizeURL: URL, redirectURL: URL, state: String? = nil, handler: OAuth2Grant, finish: @escaping FinishSession, logger: Logger?) {
        super.init(redirectURL: redirectURL, state: state, handler: handler, finish: finish, logger: logger)
        #if canImport(AuthenticationServices)
        if #available(iOS 12.0, *) {
            let authSession = ASWebAuthenticationSession(url: authorizeURL, callbackURLScheme: self.redirectURL.absoluteString) { [unowned self] in
                guard $1 == nil, let callbackURL = $0 else {
                    let authError = $1 ?? WebAuthError.unknownError
                    if case ASWebAuthenticationSessionError.canceledLogin = authError {

                return TransactionStore.shared.clear()
            }
            _ = TransactionStore.shared.resume(callbackURL, options: [:])
        })
        #endif

        _ = authSession?.start()
    }

    override func resume(_ url: URL, options: [A0URLOptionsKey : Any]) -> Bool {
        if super.resume(url, options: options) {
            authSession?.cancel()
            authSession = nil
            return true
        }
        return false
    }

    override func cancel() {
        super.cancel()
        authSession?.cancel()
        authSession = nil
    }
}
#endif
