google-api-java-client: Google Sign-In: GoogleIdTokenVerifier.verify returns null for a valid id token
Environment details
- OS type and version: Mac OS Ventura 13.3.1
- Java version: openjdk 17.0.6 2023-01-17 LTS
- version(s): 1.33.0
Description
I am integrating the Google sign-in and authenticating the id token on the backend as described here. The documentation for the GoogleIdTokenVerifier states to specify the client ids of apps (the mobile apps I believe) when instantiating the class, but when I call GoogleIdTokenVerifier.verify on the idToken (returned from the flow with the mobile app), it returns null (meaning the idToken is invalid). Specifying the web client id (which is for the server) however, works. Can this be clarified, please? Which client ids are meant to be specified when instantiating the class?
Steps to reproduce
Same steps as described here
Code example
val verifier = GoogleIdTokenVerifier.Builder(NetHttpTransport(), GsonFactory())
.setAudience(/* mobile client ids */)
.build()
verifier.verify(/* idToken from android */) // returns null instead of the GoogleIdToken instance
Stack trace
NA
External references such as API reference guides
https://developers.google.com/identity/sign-in/android/backend-auth
Any additional information below
NA
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (2 by maintainers)
Finally got the thing to work, I should mention: .setAudience() seems to accept the web_client_id (for the front end) rather than the android_client_id (supposed to be for the backend), again this is highly likely because the aud and azp are mysteriously switched for some reason. Not only that, when using Arrays.asList() as long as one of the strings is the web client ID it will work but you can also just get rid of setAudience() together and it’ll work.
For those in the future who may be reading this:
After that, I was faced with a
android.os.NetworkOnMainThreadExceptionerror, and I can’t be bothered to explain the reason so I’ll spoonfed my working code instead… Before:After:
Hopefully that helped someone… if only Google just updated their damn documentation haha
We have made the docs clearer on the fact that this is the web client token id. Please feel free to reopen if you think this still needs more clarity.
Hi @DaTigerYT. For now, I just specified the web client id (meant for the server) as part of the client ids when initializing the verifier.
The problem could also be from the client and not the verifier, but I have not had the time to verify this.