Hey I am using the Firebase auth and enabled the Google login feature.
The Google log in is working well and I get all informations. But when I want to save the user in the Firebase user-list the getIdToken()
is null:
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
//here the acct.getIdToken() is null
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(SignIn.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
progressDialog.hide();
// [END_EXCLUDE]
}
});
}
maybe you forgot to requestIdToken() on your GoogleSignInOptions object
try it:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
Your Google OAuth client credential should be for Web Application, not Android. And your Google sign in options should look something like the code below (it's C# but quite close to the Java source):
var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestIdToken("OAuth Client Id goes here")
.Build();
It should work then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With