重新验证用户凭据 Swift [英] Re-authenticating User Credentials Swift
问题描述
我希望在允许用户更改其登录信息之前重新对其进行身份验证.然而,由于最近的 Firebase 更新,我发现文档相当无用.使用 此链接 我生成了以下 authenticateUser() 函数.
I wish to re-authenticate a user prior to allowing them to change their login information. However, due to the recent Firebase update, I found the documentation rather unhelpful. Using this link I produced the following authenticateUser() function.
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 类型的凭证变量,以便重新验证用户.此类文档可以在此处找到.
However, I am unsure what to do with the credential variable of type FIRAuthCredential, in order to re-authenticate the user. The documentation for this class can be found here.
推荐答案
获取 FIRAuthCredential
对象取决于您要使用哪个提供程序重新进行身份验证.
Getting the FIRAuthCredential
object depends on what provider you want to use to reauthenticate.
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
脸书:
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.currentAccessToken().tokenString)
推特:
let credential = TwitterAuthProvider.credential(withToken: session.authToken, secret: session.authTokenSecret)
谷歌:
let authentication = user.authentication
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
这篇关于重新验证用户凭据 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!