简体   繁体   中英

ASWebAuthenticationSession is not completing

I'm using ASWebAuthenticationSession to OAuth against Facebook and everything goes well until the callback URL loads, where you would expect the completionHandler to be called but it isn't. In the end, all you can do is cancel the window.

This is a problem for either iOS 12.4 or 13.1 (latest of each major, as of writing). The function getting called is as follows:

let authURL = URL(string: url)
let callbackUrlScheme = "https://somedomain.com/authcallback"

self.webAuthSession = ASWebAuthenticationSession.init(url: authURL!,
callbackURLScheme: callbackUrlScheme, completionHandler: { (callBack:URL?, error:Error?) in
(...)
})

self.webAuthSession?.start()

In iOS 13, I'm taking care of implementing the required interface ASWebAuthenticationPresentationContextProviding and assigning the self.webAuthSession?.presentationContextProvider = context . Regardless, this problem still occurs in iOS 12. I'm lost on how to proceed with this.

Running Xcode Version 11.1 (11A1027) on macOS 10.14.6 (18G103).

So I encountered this for Microsoft MSAL library but the concept is the same. So basically the web authentication needs a defined context ie parentViewController to overlay the web view on. You most likely have deprecated message/warning and that can be traced into a objc/header file that will show you the correct method to use. Look for a method that accepts a parameter of type WebViewParameters and that will be the equivalent function.

` private var webViewParamaters: MSALWebviewParameters?

override func viewDidLoad() {

    super.viewDidLoad()

    initWebViewParams()
        acquireTokenInteractively()


}

func initWebViewParams() {
       self.webViewParamaters = MSALWebviewParameters(parentViewController: self)
}

private func acquireTokenInteractively() {

    let webViewParameters = self.webViewParamaters!

    let parameters = MSALInteractiveTokenParameters(scopes: kScopes, webviewParameters: webViewParameters)
parameters.promptType = .selectAccount;

applicationContext.acquireToken(with: parameters) { (result, error) in

    if let error = error {

        print("Could not acquire token: \(error)")
        return
    }

    guard let result = result else {

        print("Could not acquire token: No result returned")
        return
    }
    print("Access token is \(result.accessToken)")
    if error == nil {

        self.accessToken = (result.idToken)!

     } else  {
         print("Could not acquire token: \(error ?? "No error informarion" as! Error)")

     }
}
}

`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM