如何使用Google Provider重新验证Firebase上的用户? [英] How to re-authenticate a user on Firebase with Google Provider?
问题描述
示例,用于在Firebase仅显示如何重新认证使用电子邮件和密码签名的用户:
The example for using reauthenticate()
in Firebase shows only how to re-authenticate a user who signed with Email and Password:
AuthCredential credential = EmailAuthProvider.getCredential("user@example.com", "password1234");
FirebaseAuth.getInstance().getCurrentUser().reauthenticate(credential);
我还知道如何与Facebook Provider(credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().toString())
)重新进行身份验证.
I also know how to re-authenticate with Facebook Provider (credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().toString())
).
问题是Google API中没有等效的方法来获取当前的访问令牌并最终获取AuthCredential
.那么在这种情况下我该如何传递给getCredential()
?
Problem is there's no equivelant method in Google API to get the current Access Token and eventually get the AuthCredential
. So what do I pass to getCredential()
in this case?
推荐答案
我知道这是个老问题,但是我没有找到完整的答案.这是在Android上执行的操作.
I know this is old question but I did not found complete answer to this. This is how to do it on Android.
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// Get the account
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(context);
if (acct != null) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
user.reauthenticate(credential).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Reauthenticated.");
}
}
});
}
这篇关于如何使用Google Provider重新验证Firebase上的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!