我正在尝试使用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方案。在目标->信息-> URL类型中也会进行更新,如下所示:URL Types
运行上述代码后,将显示ASWebAuthenticationSession web视图,该视图为用户提供登录页面。身份验证完成后,web视图不会与WKWebView不同。在web视图的左上角有cancel选项,它会调用出错的完成处理程序。
有没有办法在身份验证会话完成后关闭webview?
发布于 2020-04-18 20:03:59
看起来您的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的其他参数
https://stackoverflow.com/questions/60702798
复制相似问题