Machine Room

Sign in with Google

Two protocols behind one button, the four steps, the two tokens that come back, and why you never registered. The one-page notes from the reel. The page shows Google's server flow; Google's ready-made button script can give the site the ID token directly.

Download the PDF

One-page notes, Sign in with Google. One button, two protocols: OAuth 2.0 + OpenID Connect. 1, Two protocols, two jobs. OAuth 2.0: what the site is allowed to access. Profile and Email ticked, Calendar and Drive padlocked; gives an access token. OpenID Connect: who you are; adds the ID token, a layer on top of OAuth 2.0. 2, The four steps, as four cards. Step 1, request: a browser with an arrow to Google; your browser is redirected to Google with client_id = which site is asking, and scope = openid email profile. Step 2, consent: log in (skipped if already logged in), pick your account, consent screen: Name, Email address, Profile picture. Step 3, code: an arrow from Google to a browser on pinecrate.example; back to the site with an authorization code, short-lived, usable once. Step 4, tokens: the site's server and Google joined by a double arrow; no browser; code + client_secret gives access_token + id_token; client_secret: provided by Google, stays on the site's server. Your Google password only goes to Google. The site never sees it. 3, Two tokens, two uses. access_token (ya29.a0…): OAuth 2.0, lets the site call a Google API, only within the scope you approved. For login: not needed. id_token (eyJhbGci…): OpenID Connect, says who you are. This is what logs you in. 4, The ID token: a JWT signed by Google. Three pieces joined by dots, eyJhbGci… the header, eyJpc3Mi… the payload, opM_8JHh… the signature. The payload as a table: iss, https://accounts.google.com, issued by Google; aud, 1234987819200.apps…, for this site (its client_id); sub, 107691503500…, your account ID: never changes, never reused; exp, 1353604926, expiry time. The site checks Google's signature first, then iss, aud and exp. 5, Why you never registered. A users table with sub, email, name: 107691503500…, jsmith@example.com, Jo Smith. Seen this sub before? The site signs you in. New? It can create your account from the ID token's details. Match users on sub, not email: your email can change, sub never does. OAuth 2.0 decides what a site may access. OpenID Connect tells it who you are.

On a phone, press and hold the image to save it.