Google Sign-In for Android Invalid ID Token

4.9k Views Asked by At

I am following the instructions on the Google Sign-In for Android guide (https://developers.google.com/identity/sign-in/android/backend-auth), and I am trying to validate my ID token. When I go to https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123 in my browser (where XYZ123 is my id token I retrieved using String idToken = acct.getIdToken();, I get this response:

{
 "error_description": "Invalid Value"
}

My id token starts with eyJ and is 1038 characters long.

I've also tried the solution here Android : Google Sign-in Invalid token to no avail.

Any help would be appreciated.

4

There are 4 best solutions below

5
VIN On BEST ANSWER

It turns out my token just expired. I grabbed a new token and it works!

0
Slobodan Antonijević On

Had the same problem. For me clearing app data completely solved the issue. Seemed like an old expired token got stuck.

0
Neerkoli On

From my own answer in another question:

In my case, I was testing this in Unity and I copied the idToken value that I printed in logcat. Turns out, there is some character or size limit (1024 bytes?) for a line in either adb logcat or Unity's Debug.Log() method. So the printed token value was getting truncated. What I did then for testing was that I copied the token value to clipboard during runtime and then checked again with the tokeninfo endpoint https://oauth2.googleapis.com/tokeninfo?id_token= and it was accepted.

0
Pratik Baid On

If the idToken that you are passing to the function is from the log of your mobile app, it is likely that you are not getting the entire idToken printed in the log due to the limitations of generic log.

I used the below code snippet to print out the idToken and used that in the API which gave me a success response.

print('ID TOKEN');
String token = googleAuth.idToken;
while (token.length > 0) {
    int initLength = (token.length >= 500 ? 500 : token.length);
    print(token.substring(0, initLength));
    int endLength = token.length;
    token = token.substring(initLength, endLength);
}

Note: Although this snippet is flutter-specific, you can reuse the logic in any framework.