rosu alin
rosu alin

Reputation: 5830

GoogleAuthProvider.getCredential method does not work for me

I am trying to follow this tutorial.

And I created this firebaseAuthWithGoogle function:

 public void firebaseAuthWithGoogle(Activity context,FirebaseAuth mAuth, GoogleSignInAccount acct) {
    Log.i(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(context, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.i(TAG, "firebase signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.i(TAG, "firebase signInWithCredential" + task.getException());
                    }
                    // ...
                }
            });
}

Which I call from here:

final GoogleSignInAccount acct = result.getSignInAccount();
        AsyncTask asyncTask = new AsyncTask() {
            @Override
            protected Object doInBackground(Object[] params) {
                try{
                    String scope =  "oauth2:" + Scopes.PROFILE;
                    Account account = new Account(acct.getEmail(), "com.google");
                    final String token  = GoogleAuthUtil.getToken(PSSignInFlowActivity.this, account, scope);                       PSSocialService.getInstance().firebaseAuthWithGoogle(PSSignInFlowActivity.this, PSApplicationClass.getInstance().mAuth, acct);
                }catch (Exception e){
                    Log.e("","firebase error trying to get client secret : " + e.getMessage());
                }
                return null;
            }
        };
        asyncTask.execute();

My idToken is: firebaseAuthWithGoogle:1024xxxxxxxxxxxxxx956 (so it is not null, added it maybe I'm not sending what I'm suppopsed too?)

But when I debug, i get this error: Must specify an idToken or an accessToken.

What am I doing wrong? They use the same logic on the tutorial PS: I am on compile 'com.google.firebase:firebase-auth:10.2.0' if it matters

EDIT: I noticed that acct.getIdToken() returns null, why is that? Shouldn't the GoogleSignInAccount have a idToken? I was logging out the acct.getId() which is the 1024xxxxxxxxxxxxx956 I wrote upper.

EDIT2: I added to my GSO this option:

 .requestIdToken(serverID)

And now I get the idToken, but I get this response back:

  04-05 10:34:16.388: I/PSSocialService(6285): firebase signInWithCredentialcom.google.firebase.FirebaseException: An internal error has occurred. [ Invalid Idp Response ]

serverID is: 264xxxxxxxxxx27.apps.googleusercontent.com Is that the correct value I should use? In the tutorial they use:

 .requestIdToken(getString(R.string.default_web_client_id))

But I tried that, and it crashes, cause It says I need to use the same clientID. I use serverID for .requestServerAuthCode(serverID) and I guess that is why

Upvotes: 0

Views: 4171

Answers (1)

rosu alin
rosu alin

Reputation: 5830

In the firebase console, for Authentification/Providers/Google it is needed to add the all external cliend ids, in order to whitelist them. This is why it would not work for me

Upvotes: 1

Related Questions