TL;DR
- An access token is what an application programming interface (API) checks before it answers. It is short-lived and meant for the API, not for the app to read.
- A refresh token quietly gets new access tokens, so it is more valuable than an access token and must be guarded harder.
- An identifier (ID) token tells the app who signed in. It belongs to OpenID Connect and should never be sent to an API as a pass.
- Most bugs come from mixing them up, and a stolen token is a reason to read what Demonstrating Proof of Possession (DPoP) does about it.
Before you start: nothing needed. If you have seen “Bearer eyJ…” in a browser tool and wondered what it was, this page is for you.
OAuth 2.0 (the standard for delegated access) and OpenID Connect (OIDC, the sign-in layer built on top) hand your app up to three different tokens. They look alike, and many of them are the same format, a JWT. They do different jobs. This page is based on the RFC 6749 and OpenID Connect Core specs.
Picture a music festival. You show your ticket at the gate and get a wristband, and you also get a voucher that you can swap for a new wristband when the first one wears out. A staff badge on a lanyard says who you are.
Access token: what the API checks#
An access token is what an application sends to an API (application programming interface) to prove it may ask. The API checks it and answers. That is the whole job.
Points to know:
- It is meant for the API. The client app should treat it as an opaque string and not build logic around what is inside.
- It is short-lived on purpose. If it leaks, the damage window is small. The provider sets the lifetime.
- It carries scopes, the named permissions the user agreed to.
- The API must check that the token was issued for it, the audience, and not accept tokens meant for other APIs. The MCP server lab shows what happens when a token is passed through an MCP server.
Refresh token: getting a new one#
A refresh token lets the app get a new access token without asking the user to sign in again. It lives longer than an access token and it goes only to the authorization server, never to an API.
That makes it more valuable. Someone who steals a refresh token can keep minting fresh access tokens. Store it carefully, and prefer providers that rotate it or tie it to the client. Not every app gets one: a quiet background service often uses its own credentials instead.
ID token: who signed in#
An ID token comes from OpenID Connect, not plain OAuth. It tells the app who just signed in, how and when. It is a JWT that the app reads: the subject, the issuer, the audience and the time.
It is for the app. It is not for an API. If you send an ID token to an API as if it were a pass, you have mixed up the badge and the wristband.
Common mix-ups that cause bugs#
- Using the ID token to call an API. APIs should reject it, and some do not.
- Reading claims out of an access token in the client and trusting them. The API owns that format and can change it.
- Putting a refresh token in a place a script or a log can read it.
- An API that skips the audience check and so accepts a token meant for someone else.
- Forgetting that a signed JWT is readable. Anyone can decode it. The signature proves it was not changed, it does not hide it.
One example#
A user opens a travel app and picks “Sign in with your work account”.
- The app gets an ID token and learns that Anna signed in.
- It gets an access token for the calendar API with the scope to read events.
- An hour later the access token expires and the app quietly uses the refresh token to get a new one.
- The calendar API only ever sees the access token.
If Anna leaves the company, the right fix is for the provider to stop honoring the refresh token. That is why refresh tokens matter more than they look.
Where to go next#
- How a token can be tied to a key so a stolen copy is useless: DPoP, PAR and RAR explained.
- How an agent trades one token for a narrower one: OAuth token exchange for AI agents.
- A lab where an API checks audience and refuses passthrough: protecting an MCP server with OAuth.
- What happens when a sign-in code is phished: device code phishing and AI agents.
Sources#
This post as Markdown · RSS · JSON feed
New posts by email
One email a week with new posts and labs. Unsubscribe anytime.
Your address is stored with Kit, which sends the emails. Details