我正在使用 Azure B2C 在我的应用程序上实现 Facebook 登录,我必须使用 SFAuthenticationSession 来执行此操作,因为 FB 不允许它在 WKWebView 内运行。
我基本上是在尝试使用从服务器端返回的 URL 实现 SFAuthenticationSession,如下所示:
https://companyName.b2clogin.com/companyName.onmicrosoft.com/oauth2/v2.0/authorize?client_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&nonce=xxxxxxx-xxxxx-xxxx-xxxxxx-xxxxxxxxxx&response_type=code&redirect_uri=https://myrul-qa.azurewebsites.net&response_mode=query&scope=offline_access%20openid%20xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx&state=xxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx&domain_hint=facebook.com&p=B2C_1_SiUpIn
问题是,我的完成处理程序没有被调用。
我的代码基本上是这样的:
var authSession: SFAuthenticationSession?
func auth(url: URL) {
authSession?.cancel()
self.authSession = SFAuthenticationSession(url: url, callbackURLScheme: nil) { (url, error) in
# this completion here is not getting called
if error != nil { return }
UIApplication.shared.open(url!)
}
self.authSession?.start()
}
如果我尝试这种方式,使用 facebook URL 而不是我的 Azure B2C URL,则会调用完成:
func auth2() {
let appID = Constant.facebookId
var components = URLComponents()
components.scheme = "https"
components.host = "m.facebook.com"
components.path = "/v2.11/dialog/oauth"
let clientID = URLQueryItem(name: "client_id", value: appID)
let display = URLQueryItem(name: "display", value: "touch")
let redirectURI = URLQueryItem(name: "redirect_uri", value: "fb\(appID)://authorize/")
components.queryItems = [clientID, display, redirectURI]
self.authSession = SFAuthenticationSession(url: components.url!, callbackURLScheme: nil) { (url, _) in
UIApplication.shared.open(url!)
}
self.authSession?.start()
}
我希望可以使用带有 SFAuthenticationSession 的 Azure B2C 调用完成。