一尘不染

重新认证用户凭证Swift

swift

我希望在允许用户更改其登录信息之前重新对其进行身份验证。但是,由于最近的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类型的凭证变量来重新认证用户。此类的文档可在此处找到。


阅读 257

收藏
2020-07-07

共1个答案

一尘不染

获取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)
2020-07-07