p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 278 forks source link

Using ASWebAuthenticationSession silently fails #345

Closed valentary closed 3 years ago

valentary commented 4 years ago

Hi, I've found an issue when trying to use the authentication session on iOS13 When specifying authorizeEmbedded and useAuthenticationSession , no embedded view ever starts and no error is given in the logs.

    @available(iOS 11.0, *)
    @discardableResult
    public func authenticationSessionEmbedded(at url: URL, withRedirect redirect: String) -> Bool {
        let completionHandler: (URL?, Error?) -> Void = { url, error in
            if let url = url {
                do {
                    try self.oauth2.handleRedirectURL(url as URL)
                }
                catch let err {
                    self.oauth2.logger?.warn("OAuth2", msg: "Cannot intercept redirect URL: \(err)")
                }
            } else {
                self.oauth2.didFail(with: nil)
            }
            self.authenticationSession = nil
        }

#if targetEnvironment(macCatalyst)
        authenticationSession = ASWebAuthenticationSession(url: url, callbackURLScheme: redirect, completionHandler: completionHandler)
        return (authenticationSession as! ASWebAuthenticationSession).start()
#else
        if #available(iOS 12, *) {
            authenticationSession = ASWebAuthenticationSession(url: url, callbackURLScheme: redirect, completionHandler: completionHandler)
            return (authenticationSession as! ASWebAuthenticationSession).start()
        } else {
            authenticationSession = SFAuthenticationSession(url: url, callbackURLScheme: redirect, completionHandler: completionHandler)
            return (authenticationSession as! SFAuthenticationSession).start()
        }
#endif
    }

In the above function, if an error is returned in the completion handler, it is never handled. If I try to implement it myself, I find that ASWebAuthenticationSession must have presentationContextProvider set to a viewcontroller that conforms to ASWebAuthenticationPresentationContextProviding, and this is why it would fail.

Regards

osorioabel commented 4 years ago

Any update on this? I have the same issue

druvv commented 4 years ago

Yes same issue as well!

marcoeig commented 3 years ago

same here