如何使用 Google Provider 在 Firebase 上重新验证用户? [英] How to re-authenticate a user on Firebase with Google Provider?
问题描述
使用reauthenticate的示例
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屋!