Check a token at your API
Have your API accept only tokens that are genuine, meant for it and still standing, by asking the realm or by checking them itself.
APIRFC 7662, RFC 9701, RFC 9068
When your API checks tokens itself rather than through the gateway, it has two ways to do it. It can ask the realm about each token by introspection, which catches a revoked token at once. Or it can check the signature itself with the realm’s published keys, which costs no call but keeps accepting a revoked token until it expires. This guide is for API teams choosing between them and setting one up.
Before you start: you know the audience your API’s tokens name, such as https://erp.example.com/api, and you’re
a realm administrator in a group holding RealmOwner, with your session in $CVYUH_SESSION
(Call the API). This guide needs no gateway.
Choose a way
Section titled “Choose a way”| Check it yourself | Ask the realm (introspection) | |
|---|---|---|
| How | Verify the signature with the realm’s keys; check iss, aud, exp, typ: at+jwt | Post the token to the realm; read active |
| Cost | No call per request | One call per request |
| A revoked token, an app a user took back, a stopped agent | Still accepted until it expires (five minutes by default), unless you also read status lists | Refused at once |
| Refresh tokens | Can’t be read | Can be checked by the client they belong to |
Ask the realm
Section titled “Ask the realm”-
Give the API a client of its own, naming its audience in
servesResources:Terminal window curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=erp-api" \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "status": "active","tokenEndpointAuthMethod": "client_secret_basic","clientSecret": "<a long random secret>","grantTypes": ["client_credentials"],"servesResources": ["https://erp.example.com/api"] }'For a key in place of a secret, see Choose how a client proves itself.
-
For each request, introspect the token, authenticated as
erp-api:Terminal window curl https://foobar.cvyuh.com/oauth2/introspect -u "erp-api:<the secret>" -d "token=<the token>" -
Accept the request only when the answer’s
activeistrue, then read who is calling from it:{ "active": true,"sub": "…", "client_id": "…", "scope": "invoices:read","aud": ["https://erp.example.com/api"], "exp": <unix time>,"principal_type": "agent", "act": { "...": "..." },"cnf": { "jkt": "…" } }
Anything not active is just { "active": false }. The API may introspect only tokens for the audiences it serves, or
issued to itself, and gets { "active": false } for anything else.
Or check it yourself
Section titled “Or check it yourself”-
Read the realm’s keys from
https://foobar.cvyuh.com/oauth2/jwks, and refresh them when a token names a key you don’t have. -
Accept a token only when it’s signed
ES256, typedat+jwt, itsissishttps://foobar.cvyuh.com/oauth2, itsaudholds your API’s audience, and it hasn’t expired. -
If the token carries
cnf.jkt, require a DPoP proof made with that key: see Bind tokens to a key.
Check it worked
Section titled “Check it worked”Send the API a token for another audience: it’s refused. Revoke a token and send it again: introspection refuses it at once; a signature check accepts it until it expires.
Related
Section titled “Related”- Introspection: every field in the answer.
- Status lists: learn of revocations within a minute, offline.
- How fast revocation takes effect: each way side by side.
- Open an API to agents: let the gateway do all of this.