And*_*ter 4 ios firebase swift firebase-authentication
我正在通过使用 OAuthProvider 类使用个人 Microsoft 帐户登录来实现 Firebase 身份验证。
我已按照以下说明操作:https://firebase.google.com/docs/auth/ios/microsoft-oauth ?authuser=0
但是,当我使用 Firebase SDK 的 OAuthProvider 时,它没有显示 Microsoft 的登录页面,实际上 getCredentialWith 没有调用任何内容。
当我使用 GoogleAuthProvider 时,一切正常,Firebase SDK 显示 Google 的登录页面。
let provider = OAuthProvider(providerID: "microsoft.com")
provider.scopes = ["files.readwrite.appfolder", "user.read"]
provider.getCredentialWith(nil, completion: { credential, error in
if let error = error {
os_log("Firebase Error: %@", type: .fault, error as CVarArg)
return
}
if (credential != nil) {
Auth.auth().signInAndRetrieveData(with: credential!, completion: { authResult, error in
if let error = error {
os_log("Firebase Error: %@", type: .fault, error as CVarArg)
return
}
})
}
})
Run Code Online (Sandbox Code Playgroud)
在全局范围内声明如下
var provider: OAuthProvider?
var authMicrosoft: Auth?
@IBAction func buttonTapped(_ sender: Any) {
provider = OAuthProvider(providerID: "microsoft.com")
provider?.customParameters = [
"prompt": "consent",
"login_hint": "",
]
provider?.scopes = ["mail.read", "calendars.read"]
provider?.getCredentialWith(nil ) { credential, error in
if error != nil {
// Handle error.
}
print(credential?.provider)
if let x = credential {
self. authMicrosoft?.signIn(with: x) { authResult, error in
if error != nil {
// Handle error.
}
print(authResult?.additionalUserInfo?.profile)
print(authResult?.user.providerID)
}
} else {
}
}
}
Run Code Online (Sandbox Code Playgroud)