Context
ADR-0021 dropped Google OAuth to save time and ADR-0023 shipped the social buttons as visual placeholders, keeping the User.googleSub column ready. The owner has now provided a Google OAuth client, so Google sign-in goes live. Apple and Twitter stay placeholders.
Decision
- Server-side authorization-code flow, split the project's way. The web owns the OAuth dance (it holds the client secret):
GET /session/googlemints astate, stores it in a short-lived httpOnly cookie, and redirects to Google;GET /session/google/callbackchecksstate, exchanges the code for a Googleid_token, and posts it to the API. The API verifies the id_token against Google's keys withgoogle-auth-library, checking the audience is ourGOOGLE_CLIENT_ID— nothing in the token is trusted before that. The web then writes the same httpOnly session cookies as email login. The token never reaches the browser. - Account resolution: match by
googleSub→ sign in; else match by email → link (setgoogleSub,emailVerifiedVia = GOOGLE); else create a STUDENT withpasswordHash = null. Google's email must beemail_verified— that is what makes aGOOGLE-verified address (unlike aSELF_ASSERTEDone) eligible to auto-join anEMAIL_DOMAINorganization later. - Env: the web reads
GOOGLE_CLIENT_ID+GOOGLE_CLIENT_SECRET; the API reads onlyGOOGLE_CLIENT_ID(optional — when unset, Google sign-in is simply unavailable and the service still boots). Redirect URI registered in the console:<origin>/session/google/callbackfor each origin (http://localhost:3100,http://localhost:8080, and production).
Consequences
- The real, tested email+password flow is unchanged; Google is an additional door that reuses the same session issuing. A
POST /auth/googleendpoint verifies and returns the session envelope. - No token or client secret is exposed to the browser. Failures (denied consent, bad state, verification error) land the user back on
/login?error=google. - Apple/Twitter remain placeholders; when they land, only
social-buttons.tsxand their own routes change.