Access tokens
Every token the realm issues for an API is a short-lived signed JWT that names its API, its caller and what it allows, so your API can check it on its own.
AvailableAPIRFC 9068, RFC 7519
Whatever grant an app, service or agent uses, what it gets for your API is the same kind of token: a JSON Web Token, signed with the realm’s key, that names the API it is for, who it is about, which client asked for it, and what it allows. Your API checks the signature against the realm’s published keys and reads the claims, with no call to the realm on each request.
Read this page when you build or configure an API that accepts the realm’s tokens, or when you decide how long tokens should live. Access tokens are short by default, five minutes, because their lifetime bounds how long a revoked user, client or agent keeps access.
Before you begin
Section titled “Before you begin”- Who can do it: a realm administrator (a group holding
RealmOwner) sets the lifetime;RealmViewercan read it. Your API needs no right: it reads the realm’s public keys. - Where: today this is done through the API (Call the API shows how to get
$CVYUH_SESSION). - First: your API knows its own name, the
resourceclients ask for it by (Resource indicators).
How it works
Section titled “How it works”The token’s header names its type, at+jwt, and is signed ES256 with the realm’s signing key. The claims, for a
user who signed in to the wiki through the browser sign-in:
{ "iss": "https://foobar.cvyuh.com/oauth2", "sub": "3f9b2c71-8d4e-4a6f-b1c2-7e5d9a0f3b48", "aud": "https://wiki.example.com/api", "exp": <iat + 300>, "iat": <unix time>, "jti": "0193a7c2-5d1e-7f00-9b3a-6c2d1e0f4a58", "client_id": "team-wiki", "principal_type": "user", "scope": "openid profile wiki:read", "sid": "6f1e2d3c-4b5a-4968-8776-a5b4c3d2e1f0"}Every token carries these:
| Claim | What it says |
|---|---|
iss | The realm that issued it |
sub | Who the token is about: a user’s ID, an agent’s ID, or the client’s own ID |
aud | The API it is for (Resource indicators) |
exp, iat | When it ends, and when it was issued |
jti | The token’s own ID |
client_id | The client that asked for it |
principal_type | What sub names: user, agent, or oauth2Client for a service acting as itself. An API never mistakes a client for a user |
Some tokens carry more, depending on how they were issued:
| Claim | When it’s there |
|---|---|
scope | The scopes granted, when any were |
authorization_details | The rich authorization details granted, when any were |
sid | The sign-in session the token ends with. Absent on a token that outlives the session (offline_access) |
family | The refresh token family it was issued under |
act | Who acts for sub, on a delegated token |
cnf | The key the token is bound to: jkt for a DPoP key, x5t#S256 for a client certificate. A token without it is a bearer token |
status | Where an API checking offline reads whether it was revoked (Status lists) |
mode, risk_class, autonomy_tier, business_owner | On a token about an agent: what a policy decides on beside who it is |
To check a token, your API:
- Reads the realm’s signing keys from
jwks_uriin the discovery document (https://foobar.cvyuh.com/oauth2/jwks), and caches them. - Checks the header’s
typisat+jwtand the signature verifies with the key the header’skidnames. - Checks
issis the realm,audnames this API, andexphasn’t passed. - Decides on
sub,principal_type,scopeand the rest.
An API that needs to know a token was revoked before it ends can introspect it, or read the realm’s status list. The gateway does all of this for an API you put behind it.
Set it up
Section titled “Set it up”There’s nothing to turn on: every grant issues these. The realm’s settings set how long they last (see Call the API):
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \ -H "Content-Type: application/json" \ -d '{ "accessTokenLifetimeSecs": 300 }'| Where | Setting | What it does |
|---|---|---|
| Realm | accessTokenLifetimeSecs | How long access tokens live, from 1 to 86400 seconds (default 300) |
Realm, keySettings | algorithm.oauth2.accessToken | The signing algorithm. ES256, the only one offered |
Limits and defaults
Section titled “Limits and defaults”| Setting or limit | Default | Range |
|---|---|---|
accessTokenLifetimeSecs | 300 (five minutes) | 1 to 86,400 |
| Signing algorithm | ES256 | ES256 only |
| A token tied to a session | ends by the session’s end | fixed |
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
| Your API refuses tokens after a key rotation | It cached the key set and doesn’t know the new kid | Fetch the key set again when a token names an unknown kid |
| Your API refuses a token as for another audience | The client asked for another API, or none and its default is another | Have the client send resource with your API’s name |
Tokens end sooner than accessTokenLifetimeSecs | The session ends first, or the agent’s risk class caps it | Expected; refresh, or check the agent’s guardrails |
invalid_token with Bearer | The token is DPoP-bound | Send it as Authorization: DPoP <token>, with a proof |
Audit record
Section titled “Audit record”Each token is one TOKEN_ISSUED record, under the user or agent it is about, with its jti (tokenId), its client,
the scopes and API granted, and the key it is bound to. Find one token by its jti on the principal’s trail
(Read a user’s or agent’s trail). A change to the lifetime is in
Audit → Config.
Good to know
Section titled “Good to know”- Only an asymmetric algorithm signs them. No shared-secret algorithm is offered, because every API that checks a token would then hold the key that makes them.
- A token never outlives its session. A token tied to a session (
sid) has its lifetime cut to the session’s end, and ends with it when the user signs out (Logout). - An agent’s token can be shorter. The realm’s agent guardrails cap its life by the agent’s risk class.
- The token’s claims are for the API, not the app. An app learns who signed in from the ID token and userinfo, never by reading the access token.
- The keys rotate. Fetch the key set again when a token names a
kidyou don’t hold (Signing keys).
Related
Section titled “Related”- Set how long tokens live: the task, start to finish.
- Resource indicators: how a token comes to name one API.
- Introspection: ask the realm whether a token still stands.
- DPoP: make a copied token useless without the client’s key.