簡體   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