2

I am integrating Google sign-in for Android and I want the id_token back so I can authenticate with my server. I followed all the steps as in https://developers.google.com/identity/sign-in/android/backend-auth

If I request just requestEmail() then I am getting back the profile information but if I add .requestIdToken(getString(R.string.server_client_id)) then result.isSuccess() is false and I am not getting any account information back. Any ideas?

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(getString(R.string.server_client_id))
            .build();

onActivityResult:

            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                    GoogleSignInAccount acct = result.getSignInAccount();
                    String idToken = acct.getIdToken();
                    mIdTokenTextView.setText("ID Token: " + idToken);
                    // TODO(user): send token to server and validate server-side
            } else {
                    mIdTokenTextView.setText("ID Token: null");
            }

If I try to call any method on "result" then I get a Null pointer error...

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=0, data=Intent { (has extras) }} to activity {com.test.LoginActivity}: java.lang.NullPointerException

LAX_DEV
  • 2,111
  • 3
  • 19
  • 29
  • Have you already done stuffs in google developer console? – Nabin Jul 20 '17 at 08:02
  • see into "result.getStatus().getStatusMessage()" here you should find error message – an_droid_dev Jul 20 '17 at 08:32
  • @an_droid_dev I am getting Null pointer error.. java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=0, data=Intent { (has extras) }} to activity {com.test.LoginActivity}: java.lang.NullPointerException – LAX_DEV Jul 20 '17 at 08:45

2 Answers2

14

SOLVED!

So after 6 hrs of breaking my head, found the issue. Apparently when you create config.json using your SSH1 google automatically creates a Web OAuth2 key associated with this project. What I noticed was Google created 3 projects with the same name (one for firebase, one for Web and another not sure)

So grab the Web client ID that is linked with the same Android project. Oh Google!

LAX_DEV
  • 2,111
  • 3
  • 19
  • 29
0

I have found after researching about this issue and found that result is throwing null pointer Exception due to android:launchMode="singleInstance" in activity manifest.

So make sure you Change launchmode to 'singleTop' or just dont give any launchmode for the your activity for e.g: signinActivity;

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
  • This answer makes no sense because he never published his `manifest` – Steven Nov 19 '17 at 07:19
  • This answer really does the job. On JellyBean the login failes in singleInstance mode, but succeedes in singleTop, while on Oreo it works in both modes. – pfaehlfd Dec 22 '17 at 14:03