Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Token formats and validation

Before the photo API can decide whether the printer may see album 42, it has more basic questions to answer about the token in the request. Did the photo service's authorization server issue it? Was it issued for this API? Is it still valid? How the API answers depends on what the token contains, and this lesson compares the two formats and follows the checks for the self-contained one.

Reference and self-contained tokens

The printer's request reaches the photo API with a token in its Authorization header. Some tokens carry nothing but a reference. Others carry their own description, signed by the authorization server.

A reference token, often called an opaque token, is a random string that points to a record kept by the authorization server. demo-access-token-7 could be one, and only the authorization server knows what it stands for. An API that receives one has to ask the authorization server what it means, which the Token introspection lesson covers.

A self-contained token carries that information itself. The common format is a signed JWT. The authorization server writes the claims and signs them with its private key, and any API holding the matching public key can check the token without contacting anyone.

Neither format is better everywhere:

How the two formats compare for the photo API
ConsiderationReference tokenSelf-contained JWT
SizeA short random string.Hundreds of characters or more, sent with every request. The example below is 423.
Who can read itOnly the authorization server knows what it means.Anyone holding it can decode the claims, including the client and anything that logs it.
RevocationTakes effect at the API's next check with the authorization server.An API that validates locally accepts the token until it expires.
Dependence on the authorization serverEvery check needs the authorization server to answer, unless the API caches the result.The API needs only the issuer's public keys, so it keeps working through a short outage.

The revocation row is the one people discover in production. If Ava disconnects the printer at 09:02 and its JWT expires at 09:10, an API that validates locally keeps accepting that token for eight more minutes, because nothing in the token has changed. Short lifetimes keep that window small.

The privacy row is easy to overlook too. A JWT carrying Ava's email address would hand it to every client that received the token, so the authorization server chooses what goes into a self-contained token knowing who can read it.

The JWT access token profile

Inside a JWT took a token apart into its header, payload and signature and listed the registered claims. JWT access tokens add a standard profile on top, so APIs and authorization servers agree on what each claim means in an access token. If the photo service issued JWTs, the printer's token, shown in Exchanging a code for tokens as the stand-in demo-access-token-7, would look like this, shortened for display. All domains, keys and tokens in these examples are fictional.

eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0
.eyJpc3MiOiJodHRwczovL2F1dGgucGhvdG9zLmV4YW1wbGUiLCJzdWIiOiJ1c2VyLTIwNDgi...
.(signature)

The line breaks are for display. Decoded, its header and claims read:

Header:
{
  "alg": "ES256",
  "kid": "photos-2026-09",
  "typ": "at+jwt"
}

Claims:
{
  "iss": "https://auth.photos.example",
  "sub": "user-2048",
  "aud": "https://api.photos.example",
  "client_id": "photo-printer",
  "scope": "photos.read",
  "iat": 1790845200,
  "exp": 1790845800,
  "jti": "demo-token-id-7"
}

The header's typ, at+jwt, is the profile's own value: it declares that this JWT is an access token, not some other kind of token from the same issuer.

The claims describe the access. iss is the authorization server's issuer identifier. sub is the subject, here Ava's account at the photo service, user-2048; in a token a client obtained for itself with the client credentials grant, it normally identifies the client instead. aud, the audience, names the API the token is for, and client_id the client it was issued to, so a token carries both whose access it is and which application is using it. scope is the space-separated list of granted scopes. iat and exp are 09:00 and 09:10 UTC on 1 October 2026, and jti gives this token a unique identifier.

The profile requires every one of those claims except scope, which a server should include whenever the client requested one.

Validating step by step

Reading a token is not validating it, as Protecting credentials and messages first put it. The JOSE lessons set out how a receiver gets from a decoded JWT to an accepted one, and the photo API applies those checks with its own expected values, in this order, before it trusts any claim:

  1. Accept only the expected algorithm. The API's configuration says ES256 for this issuer, and a token naming anything else, none included, is refused. Choosing and enforcing algorithms explains why the header never chooses.
  2. Check the type. typ must be at+jwt, or its long form application/at+jwt. The photo service also signs the ID tokens OpenID Connect gives clients after sign-in, and publishes their keys in the same key set. It happens to sign them with a different algorithm, but nothing requires that, so only this check reliably keeps another kind of JWT from passing as an access token when its other claims happen to fit.
  3. Find the key. The API looks up the token's kid in the photo service's key set at https://auth.photos.example/jwks, an address from its own configuration or the issuer's metadata, and never uses a key the token offers itself, as JWKs, key sets, and key IDs explained.
  4. Verify the signature with that key and the expected algorithm.
  5. Check the issuer. iss must equal https://auth.photos.example exactly, with no adjustments for case or a trailing slash. An API that trusts several issuers must also confirm that the key it used belongs to the issuer the token names.
  6. Check the audience. aud may be a single value or a list, and one of its values must be the photo API's own identifier, https://api.photos.example. A genuine token issued for another API is still rejected: its signature proves who issued it, not who it was for.
  7. Check the time. The current time must be before exp, and not before nbf ("not before") when the token has one. A small tolerance absorbs differences between the two servers' clocks, which the profile describes as usually no more than a few minutes.

The values are what make these checks the photo API's own. The algorithm, the issuer, the key set address and the audience all come from its configuration, never from the token, which is why each needs setting explicitly: these checks are settings for a well-maintained JWT library rather than code to write by hand, and a library left on its defaults may skip some.

If any check fails, the API answers 401 with invalid_token, and the request goes no further. A token that passes has proved who issued it, which API it was for, and that it is current. It has not yet been compared with what the printer is asking to do: first the scope, then the album.

The photo API works through the checks in order and stops at the first one that fails. An unfamiliar key identifier sends it back to the key set before the token is rejected.

Keeping up with keys

Fetching the key set for every request would make the authorization server part of every API call, so the photo API caches it and follows the rules from Caching the key set: fetch the set again when a token names an unfamiliar kid, and limit how often that can happen. If the identifier is still unknown after a fresh fetch, the token is rejected.

Those rules let the photo service rotate its access token signing key without coordinating with each API. Before it signs anything with its next key, it publishes that key beside the current one:

GET /jwks HTTP/1.1
Host: auth.photos.example

HTTP/1.1 200 OK
Content-Type: application/json

{
  "keys": [
    { "kid": "photos-2026-09", "kty": "EC", "crv": "P-256", "alg": "ES256", "use": "sig", "x": "...", "y": "..." },
    { "kid": "photos-2027-01", "kty": "EC", "crv": "P-256", "alg": "ES256", "use": "sig", "x": "...", "y": "..." },
    { "kid": "photos-rs-2026-09", "kty": "RSA", "alg": "RS256", "use": "sig", "n": "...", "e": "AQAB" }
  ]
}

The key values are shortened here. The third key, photos-rs-2026-09, signs ID tokens and is not part of this rotation. An API that refreshed its cache after the new key appeared already knows photos-2027-01. One that has not sees an unfamiliar identifier on the first new token, fetches the set again, and finds it. The old key stays published until the last token it signed has expired, ten minutes after the switch with these tokens.

The cache has a cost in the other direction. If a signing key leaks, the photo service removes it from the set immediately, but an API keeps trusting its cached copy until its next scheduled refresh. The unfamiliar-identifier rule never fires, because tokens signed with the leaked key name a key the API already knows. The cache lifetime therefore decides how long a withdrawn key keeps working at that API, and a refresh measured in minutes or an hour, rather than days, keeps the window short.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

A JWT reaches the photo API. Its signature verifies with one of the photo service's keys, but its aud names a different API. What should the photo API do? 1 of 3

Choose one answer.

The photo API validates JWT access tokens locally. Ava disconnects the printer at 09:02, and its token expires at 09:10. What happens to the printer's request at 09:05? 2 of 3

Choose one answer.

A token reaches the photo API naming kid photos-2027-01, which is not in the key set the API cached this morning. What should the API do? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity