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);
I also know how to re-authenticate with Facebook Provider (credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().toString())
).
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?
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.");
}
}
});
}