Closed stnor closed 6 years ago
The authorize
callback is called as soon as you're authorized, it doesn't wait for UI actions. If you need control over UI actions, you can turn off auto-hide, hide the view yourself when the callback comes in so you have more control. Something along:
oauth.authConfig.authorizeEmbeddedAutoDismiss = false
oauth.authorize(params: ["aud": server.aud]) { parameters, error in
if let vc = oauth.authConfig.authorizeContext as? UIViewController {
vc.dismiss(animated: true) {
// callback when dismiss animation is done
}
}
}
Thanks so much. That works great.
/Stefan
I didn't actually manage to get this to work reliably as per your suggestion.
I ended up with the following which works every time:
let url = try! oauth2.authorizeURL(params: nil)
let authorizer = oauth2.authorizer as! OAuth2Authorizer
let web = try! authorizer.authorizeSafariEmbedded(from: view, at: url)
oauth2.afterAuthorizeOrFail = { authParameters, error in
web.dismiss(animated: true) {
self.validateToken(authParameters: authParameters, error: error, completion: completion)
}
}
If authorize() need to present the embedded web view (eg there is no valid token), I need to use a 1s delay for performSegue in my vc for it to succeed. Otherwise I get the following error:
What am I doing wrong?
I can't spot the error in my code, so I wonder if the callback from authorize() can come before the embedded view is properly closed?
Non-embedded works great. I've also tried authorizedEmbedded(from: view), same result as above.
Thanks, Stefan
Code involved:
AppDelegate: