重新验证用户凭据斯威夫特 [英] Re-authenticating User Credentials Swift

查看:168
本文介绍了重新验证用户凭据斯威夫特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给用户,让他们改变自己的登录信息之前重新进行身份验证。然而,由于近期火力地堡更新,我发现文件而无益的。使用此链接我产生了以下的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的凭据变量,以重新验证用户。这个类的文档,可以发现<一个href=\"https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_auth_credential#properties\"相对=nofollow>这里。

推荐答案

获取 FIRAuthCredential 对象取决于您要使用重新认证什么提供商。

Getting the FIRAuthCredential object depends on what provider you want to use to reauthenticate.

let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)

Facebook的:

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)

这篇关于重新验证用户凭据斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆