我希望在允许用户更改其登录信息之前重新对其进行身份验证。但是,由于最近的Firebase更新,我发现文档没有帮助。使用此链接,我产生了以下authenticateUser()函数。
func authenticateUser() { let user = FIRAuth.auth()?.currentUser var credential: FIRAuthCredential //prompt user to re-enter info user?.reauthenticateWithCredential(credential, completion: { (error) in if error != nil { self.displayAlertMessage("Error reauthenticating user") } else { //user reauthenticated successfully } }) }
但是,我不确定如何使用FIRAuthCredential类型的凭证变量来重新认证用户。此类的文档可在此处找到。
获取FIRAuthCredential对象取决于要用于重新认证的提供程序。
FIRAuthCredential
let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)
let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
let credential = FIRTwitterAuthProvider.credentialWithToken(session.authToken, secret: session.authTokenSecret)
let authentication = user.authentication let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken, accessToken: authentication.accessToken)