Skip to content
GatewayMarkdown

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.

Check it yourselfAsk the realm (introspection)
HowVerify the signature with the realm’s keys; check iss, aud, exp, typ: at+jwtPost the token to the realm; read active
CostNo call per requestOne call per request
A revoked token, an app a user took back, a stopped agentStill accepted until it expires (five minutes by default), unless you also read status listsRefused at once
Refresh tokensCan’t be readCan be checked by the client they belong to
  1. 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.

  2. 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>"
  3. Accept the request only when the answer’s active is true, 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.

  1. 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.

  2. Accept a token only when it’s signed ES256, typed at+jwt, its iss is https://foobar.cvyuh.com/oauth2, its aud holds your API’s audience, and it hasn’t expired.

  3. If the token carries cnf.jkt, require a DPoP proof made with that key: see Bind tokens to a key.

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.