Identity and access OpenID Connect (OIDC) 4 min read
What happens when you sign in with Google?
Tasklane, a to-do app, greets you by name the first time you sign in with Google. You’ve never set a Tasklane password.
-
A note from Google, signed
Google gives Tasklane an ID token: a signed note saying who you are. You sign in on Google’s own page, so Tasklane never sees your password.
Tasklane starts by sending you to Google with a request that says “I’m tasklane-web, tell me who this is.” The
openidscope asks Google to use OpenID Connect (OIDC), the rules that define how to issue and verify that ID token.Tasklane sends you to Google asking who you are. You sign in on Google’s page. Google sends Tasklane a signed ID token for tasklane-web, and Tasklane checks it before letting you in.
Your password only ever goes to Google. In short An ID token tells your app who signed in, without your password.
-
What the token says
An ID token is a signed list of claims.
issis who wrote it, herehttps://accounts.google.com.subis a stable ID for Priya that never changes.audis who it’s for: Tasklane’s client ID.expis when it stops being valid.There’s often an
emailtoo. It’s handy for showing on screen, but emails change and get reused, so identify people bysub.In short Use sub to know who someone is, not their email.
-
Four checks before trusting it
The signature must check out with Google’s public key; change one letter and it fails.
issmust be an issuer Tasklane set up, andgoog1e-auth.comisn’t one.audmust be Tasklane’s own client ID; a token made forquizpal-appwould let any app Priya uses sign in as her here.And
expmust still be in the future. Expired a minute ago counts as expired.Four lines, four questions. One “no” and the token stays out. In short Check who signed it, who it’s for, and when it expires.
What an ID token isn’t
It isn’t a key for your API. Tasklane’s API receiving an ID token should refuse it: its aud is tasklane-web, the app that asked for sign-in, not the API.
An ID token tells the app who signed in. To call an API, the app sends an access token, which the API checks under its own rules.
Keep this
Before trusting an ID token, check who signed it, who it’s for and when it expires.
It tells your app who signed in. It isn’t a key for your API. Calling an API is the access token’s job.- Signed by
- The signature checks out with the issuer’s public key, and iss is an issuer you set up.
- For
- aud is your own app’s client ID.
- Fresh
- exp is still in the future.
- Limit
- An ID token signs the user in to your app. It isn’t a key for your API.
Questions worth carrying
Is OIDC a replacement for OAuth?
No. OAuth lets an app get access to something. OIDC adds a standard way to learn who signed in, on top of OAuth.
Where does Tasklane get Google’s public key, and what happens when Google changes it?
From a key set Google publishes, listed in its OpenID discovery document. Keys change from time to time, so apps fetch and cache them by key ID instead of hard-coding one.
What’s a “nonce”, and what attack does it stop?
A random value the app sends with the sign-in request and expects back inside the ID token. It stops someone from replaying an old token into a new sign-in.
If Priya logs out of Google, is her Tasklane session over too?
Not by itself. After sign-in, Tasklane runs its own session. Ending both takes extra work, such as OIDC’s logout features.
A phone app can’t keep a secret. How does it get tokens safely?
With PKCE. The app proves that the code it trades for tokens came from the same app that started the sign-in, without needing a stored secret.