Token introspection
A reference token carries nothing an APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. can check, so the API has to ask the authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. what the token stands for. This lesson follows the photo API as it asks, reads active and inactive answers, caches them without letting a revocationCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. linger, refuses requests when no answer comes, and limits what each answer reveals.
Reading the answer
For the printer's token, which acts for Ava's account user-2048, the authorization server answers:
HTTP/1.1 200 OK
Content-Type: application/json
{
"active": true,
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "https://api.photos.example",
"client_id": "photo-printer",
"scope": "photos.read",
"token_type": "Bearer",
"iat": 1790845200,
"exp": 1790845800
}The fields carry the same meanings as the claims in a JWT access token, and iat and exp are the same Unix timestamps in seconds. Only active is required. Which of the others appear is up to the authorization server.
For every token that should not be accepted, the answer is the same:
HTTP/1.1 200 OK
Content-Type: application/json
{
"active": false
}Expired, revoked, never issued, or one this API is not allowed to ask about, such as a token meant for another API: all of them produce "active": false, and the specification says the server should not attach a reason. That is deliberate. A caller told "revoked" rather than "never existed" learns something about the server's records. The photo API passes the same uniformity on, answering the printer with 401 and invalid_token whatever the cause. The authorization server can still record the real reason in its own logs, where only its operators read it.
"active": true means the token is genuine and current. It does not mean this request is allowed. The API still checks that aud names it, when the response includes an audience; a server that tailors its answers may already have answered false for a token meant elsewhere, but the API does not depend on that. It then checks the scope against the operation and the album against the subject, exactly as in Enforcing access at an API. Introspection replaces the signature and claim checks, not the authorization decision.
Some deployments need a record of the answer that can be verified later, not just one received over a protected connection. A separate standard, RFC 9701, lets the authorization server return the same information as a JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. it has signed.
Caching and freshness
An introspection call on every API request adds a network round trip to each one, and it makes the authorization server part of every request path. The API can cache answers, at a price.
A cached "active": true keeps working even if the token is revoked a moment later. The cache lifetime is exactly the window in which a revoked token still works at this API. The specification leaves the balance to each deployment, with one firm rule: an answer that includes exp must not be cached past that time. Within that limit, the photo API might keep answers for a minute when photos are being read, and introspect afresh before every deletion, so a revoked token could read for at most another minute and never delete anything. The cache is keyed by a hash of the token rather than the token itself, so a memory dump or a debugging tool does not reveal working tokens.
The harder question is what to do when the authorization server does not answer. A timeout, a server error, or a refused connection says nothing about the token. Accepting the request anyway, failing open, would let any string through during an outage, including tokens revoked minutes before. The photo API fails closed: it refuses requests it cannot verify.
The introspection standard leaves the API's answer in this case to the API. The photo API's choice is 503 Service Unavailable, the HTTP status for a server that cannot handle a request right now, which describes the refusal better than a 401. The token may be perfectly good, and telling the printer it is invalid would send the printer off to replace a token that was never the problem. The same goes for an API whose own client secret the authorization server refuses: it has learned nothing about the token, so it answers 503 too. Answers already in the cache can still be used until their normal expiry, but not stretched beyond it to ride out the outage.
What the response reveals
An introspection response can describe a person: an account identifier, sometimes a username, which client they connected, and what they allowed it to do. Every API that can introspect learns this about every token presented to it. The specification requires measures against disclosure to unintended parties, and the simplest measure is to send less.
The photo service tailors each answer to the caller:
| Caller | Asks about | Answer |
|---|---|---|
The photo API, a resource server for https://api.photos.example | The printer's access token, meant for the photo API | Active, with the fields the photo API needs |
| The sharing API, a resource server for another audience | The same access token | "active": false |
| The photo API | The printer's refresh token | "active": false |
| The printer, the client the tokens were issued to | Its own refresh token | Active, with its scope and expiry |
A client may always ask about its own tokens. An API needs to know about the access tokens presented to it and nothing about a client's refresh tokens, which never go to an API at all. A service that wants to stop its APIs from correlating activity can go further and give each API a different subject identifier for the same person, so the identifier the sharing API sees for Ava has no visible connection to user-2048. A field that is never sent never needs protecting.
The API handles what it receives with matching care. The response, like the token in the request, does not belong in ordinary logs. A record that a token was active, for which client and subject, and what the API decided, answers the questions a later investigation will ask.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Validate reference tokens by introspection, with a cache that fails closedIntrospect the printer's opaque tokens as the photo API, compare what other callers learn, measure the cache window after Ava disconnects, then see the API refuse when introspection fails.