Repository navigation
fix(android): sign in with Google through a backend-verified ticket - #295
Merged
Merged
Conversation
Clerk refuses every ID token the Android Google picker returns, for sign-in and sign-up alike, because the token's azp names the Android OAuth client. The picker cannot mint one without it, so native Google sign-in never worked. The backend now verifies the token itself (Google's keys, our web client as audience, our Android clients as azp, verified email), finds the Clerk user who linked that exact Google account, and returns a 60-second sign-in ticket the app redeems. Email only narrows the lookup; an admin-asserted address never proves ownership. With no linked account the app continues to Clerk's web OAuth, which is where sign-up happens. Also fixes two picker bugs: the app opened the web login on top of the picker after 10 seconds or on cancel, and the plugin reused the last Google account so nobody could switch. Needs GOOGLE_WEB_CLIENT_ID and GOOGLE_ANDROID_CLIENT_IDS in the managed backend env; until both are set the route 404s and the app uses web OAuth.
…actor Also time out the Google certificates request after five seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Google sign-in in the Android app has never worked. Clerk refuses every ID token the Google picker returns with
authorization_invalid, for sign-in and sign-up, because the token'sazpnames our Android OAuth client. Android's picker cannot mint a token without it.Confirmed on a Pixel 8 Pro against production Clerk on 2026-10-21:
google_one_tap_token_invalid. A real one passes and is then refused, so the problem isn't the token.Kallb123/async-games#663 hit the identical refusal and fixed it the same way.
What changes
Backend:
POST /api/auth/google-native(public, strict auth rate limit)azpis one of our Android clients.email_verifiedis true.sub) linked and verified through Clerk's own OAuth. Email only narrows the search. An admin-asserted address on a Clerk user never proves ownership: this is the takeover hole called out in the async-games PR.{ ticket: null }when no account has that Google login linked.App (
signInWithNativeGoogle, shared by the sign-in and sign-up forms)signIn.create({ strategy: "ticket" }).google_one_tapattempts, none of which could succeed.Picker bugs fixed along the way
Deploy
The managed backend env (
MANAGED_BACKEND_ENV_FILEin the infra repo) needs:These are client IDs, not secrets. Until both are set, the route 404s and the app uses web OAuth as before.
Testing
google-native.test.tssigns real RS256 tokens with throwaway keys. It covers a foreign signing key, wrong audience, a foreign or missingazp, an unverified email, a foreign issuer, an expired token,alg: noneand an unknown key ID. On the lookup side it covers an email-only match, a different Google account on the same address, and an unverified link. Each guard was mutation-checked: removing it fails a test.