【发布时间】:2019-05-23 05:07:34
【问题描述】:
我对 Swift 和 Firebase 还很陌生,我正在尝试让 Microsoft OAuth 提供程序按此处所述工作:
https://firebase.google.com/docs/auth/ios/microsoft-oauth?authuser=0
我的应用在运行时是稳定的,但是 MSLoginTapped 按钮什么也不做,在调试时我只能看到 provider.getCredentialWith 似乎没有运行,因为我没有收到我的打印语句。
文档中似乎存在多个错误,因此我尽可能地对其进行了修改,并提交了审查文档的请求。
Firebase 文档 sn-p:
provider.getCredentialWithUIDelegate(nil) { credential, error in
if error != nil {
// Handle error.
}
if credential != nil {
Auth().signInAndRetrieveData(with: credential) { authResult, error in
if error != nil {
// Handle error.
}
// User is signed in.
// IdP data available in authResult.additionalUserInfo.profile.
// OAuth access token can also be retrieved:
// credential.accessToken
}
}
}
问题 1:provider.getCredentialWithUIDelegate 无法识别。
问题 2:Auth().signInAndRetrieveData 无法识别。
================================================ ===
这是我正在使用的东西(那是行不通的):
class LoginViewController: UIViewController {
var ref : DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func MSLoginTapped(_ sender: UIButton) {
let provider = OAuthProvider(providerID: "microsoft.com")
provider.getCredentialWith(nil) { (credential, error) in
if error != nil {
// Handle error.
print("Failed to retreive credential.")
return
}
if credential != nil {
Auth.auth().signInAndRetrieveData(with: credential!) { authResult, error in
if error != nil {
// Handle error.
}
// User is signed in.
// IdP data available in authResult.additionalUserInfo.profile.
// OAuth access token can also be retrieved:
// credential.accessToken
}
} else {
print("Credential is nil.")
}
}
}
}
【问题讨论】:
标签: ios swift firebase oauth firebase-authentication