Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleSignInAccount getIdToken() is null

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]
          }
      });

}
like image 900
Finki Avatar asked Apr 03 '17 07:04

Finki


2 Answers

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();
like image 126
Felipe Cintra Ferraz Avatar answered Sep 19 '22 20:09

Felipe Cintra Ferraz


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.

like image 23
Rafael Pereira Avatar answered Sep 20 '22 20:09

Rafael Pereira