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

问题描述 投票:0回答:1

我正在尝试使用ASWebAuthenticationSession 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方案。在Tar​​gets-> info-> URL Types中更新了相同的内容看起来像:URL Types

运行上述代码后,将显示ASWebAuthenticationSession Web视图,该视图为用户提供了登录页面。身份验证完成后,不会像WKWebView一样关闭Web视图。Web视图的左上方有一个cancel选项,它会错误地调用完成处理程序。

完成身份验证会话后,是否有办法关闭Webview?

ios swift webview completionhandler aswebauthenticationsession
1个回答
0
投票

似乎您在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-urls

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.