繁体   English   中英

未为 ASWebAuthenticationSession 调用会话完成处理程序

[英]Session completion handler not being called for ASWebAuthenticationSession

我正在尝试使用 ASWebAuthenticationSession Web 视图。 身份验证完成后,不会调用会话完成处理程序。 因此,Web 视图不会关闭。

guard let authURL = URL(string: "https://github.com/login/oauth/authorize?client_id=<client_id>/") 
else { return }
let scheme = "octonotes"
session = ASWebAuthenticationSession.init(url: authURL, callbackURLScheme: scheme, completionHandler: { callbackURL, error in
       // Handle the callback.
       print(callbackURL!)
       print(error!)      
        })
session?.presentationContextProvider = self
session?.start()

我已经在 info.plist 中设置了回调 url 方案。 同样在 Targets -> info -> URL Types 中更新它看起来像: URL Types

运行上述代码后,会出现ASWebAuthenticationSession web view,为用户提供登录页面。 身份验证完成后,与 WKWebView 不同,Web 视图不会关闭。 Web 视图的左上角有取消选项,它调用完成处理程序时出错。

身份验证会话完成后,有没有办法关闭 webview?

看起来您的 authURL 中缺少重定向 URI - 因此 GitHub 不知道将成功的身份验证重定向到何处。

尝试这个:

let scheme = "octonotes"
guard let authURL = URL(string: "https://github.com/login/oauth/authorize?client_id=<client_id>&redirect_uri=\(scheme)://authcallback")

请记住,您可能还缺少其他一些参数,请在此处查看您可以提供的其他参数https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#redirect-网址

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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