Resource server responsibilities
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. that accepts tokens stays correct only while the facts it depends on stay correct: which issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts. it trusts, the keys that issuer signs with, its own clock, and the scopes clients ask for. Its team needs to notice quickly when one of them changes.
Trusting the right issuer
The photo API validates every tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. it receives and decides every request, as the Tokens and resource servers lessons described. That code is written once, but the facts it depends on keep moving: 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. rotates its keys, the API gains a staging copy, server clocks drift, and the photo service decides its scopes need redesigning.
All domains and identifiers in these examples are fictional. The photo service runs its API in two environments, each with its own authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. server:
| Setting | Production API | Staging API |
|---|---|---|
| Trusted issuer | https://auth.photos.example | https://auth.staging.photos.example |
| Expected audience | https://api.photos.example | https://api.staging.photos.example |
| Accepted algorithm | ES256 | ES256 |
| Clock leeway | 30 seconds | 30 seconds |
Each API trusts exactly one issuer, and that value comes from its deployment configuration, never from anything inside a token. The production API does not also accept staging tokens for convenience during testing. Staging authorization servers tend to have test accounts with known passwords, relaxed policies, and more people with administrative access. A production API that accepted their tokens would give all of those people a way into real photo libraries.
The key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys. address is not configured separately. The API reads jwks_uri from its trusted issuer's metadata, so the issuer and its keys cannot drift out of step. A deployment check that sends a correctly signed staging token to the production API, and expects a rejection, catches a mixed-up configuration before customers or attackers do.
Keys, clocks, and caches
Token formats and validation explained how the API selects a key by kid and fetches the key set again when it meets one it does not know. Operating that mechanism means making sure it can work when it is needed. The API's network rules must allow it to reach the key set address. Nobody should paste a single public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt. into its configuration as a shortcut, because that copy will not change when the photo service starts signing with photos-2027-01. Rejections for an unknown kid deserve their own alert: a few may be forgeries, but a wave of them just after a rotation means the API is not seeing the new key.
Lifetime checks depend on the API's own clock. Token formats and validation also described the small tolerance that absorbs clock differences. The photo API allows thirty seconds, and each of its servers keeps time with a network time service so that the tolerance rarely matters. A server whose clock drifts further than that starts rejecting fresh tokens as expired, or accepting expired ones, and only that server does so, which makes the fault look random. Monitoring each server's clock offset turns it into an ordinary alert.
Several things are cached: the metadata document, the key set, and, where the API introspects, recent introspectionA way for an API to ask the authorization server what a token means: whether it is still active and what access it carries. APIs need it when a token is a random string that only the authorization server can interpret. results. Each cache needs a maximum age and a decision about what happens when it cannot refresh. For the key set, the sensible choice is to keep using the cached keys and raise an alert. For introspection results, Token introspection set a stricter rule: a cached answer is never stretched past its normal lifetime, and a token that cannot be checked is refused.
Changing scopes without breaking clients
Years ago, the photo service offered a single scope called photos that allowed reading, uploading, and deleting. It now offers photos.read, photos.write, and photos.delete, and wants the old scope gone. Some clients still request it, and refresh tokens issued under it are still producing access tokens.
A change like this runs in stages:
- Add. The new scopes go live. The API accepts them, and for now it still treats
photosas satisfying any of them. - Measure. The API and the authorization server count which clients still request or present
photos, byclient_id. - Stop new grants. New registrations cannot request the old scope, and the developers of existing clients are asked to switch.
- Announce a date. Each remaining client's developers hear when the old scope stops working and what their users will see.
- Remove. After the date, the API no longer accepts
photos, and grants that still carry it need the person's approval again.
The order matters because tokens outlive deployments. An access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. issued at 08:59 with photos in its scope is still presented at 09:05, and a refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again. issued last year can keep producing tokens with the old scope until its grant changes. The API keeps accepting both until the measurements show the old scope has stopped arriving or the announced date has passed.
The API also describes itself. Some APIs publish protected resource metadata: a JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. document at a well-known address, here https://api.photos.example/.well-known/oauth-protected-resource, naming the authorization servers the API trusts and the scopes it understands. The Protected resource metadata lessons in Advanced OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. cover it in full. When the photo API publishes one, its scopes_supported list changes in the same release as the scopes, and generating the document from the configuration the API enforces keeps the description and the behavior from drifting apart.
- API accepts photos
- Yes
- New grants may request photos
- Yes
- Token from an old grant
- Accepted
- API accepts photos
- Yes
- New grants may request photos
- Yes
- Token from an old grant
- Accepted and counted by client_id
- API accepts photos
- Yes
- New grants may request photos
- No
- Token from an old grant
- Accepted
- API accepts photos
- Yes
- New grants may request photos
- No
- Token from an old grant
- Accepted until the date
- API accepts photos
- No
- New grants may request photos
- No
- Token from an old grant
- Needs the person's approval again
The order matters because tokens outlive deployments.
Watching rejections and outages
Every rejection the API returns is a small piece of evidence, and counted by reason and by client they become useful. Expired tokens from one client suggest it is not replacing tokens before they expire. insufficient_scope from another suggests it never asked for the access it now uses. Tokens with the wrong audience may mean a client is sending tokens meant for another API, or that someone is replaying tokens taken from elsewhere. The decision records described in Enforcing access at an API already hold the reason and the client. Counting them, and alerting when a count jumps, is what turns those records into monitoring.
The API also needs a plan for the hours when the authorization server is unavailable. Local JWT validation keeps working with cached keys, while anything that depends on introspection fails closed, as Token introspection explained. The plan decides in advance which routes are which, sets short timeouts so a slow authorization server does not tie up every request the API is handling, and spaces out retries so that thousands of introspection calls do not arrive together the moment the authorization server recovers.
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
- Run a production and a staging API and keep their facts correctPin each API to one issuer, find its keys from metadata, rehearse clock drift, migrate a scope in stages without breaking a client, and fail closed through an introspection outage.