# Status lists

> An API that checks tokens offline still learns within a minute that one was revoked, from a small signed list it fetches.

An API that checks token signatures itself never asks the realm, so a revoked token works there until it expires.
With status lists, each token carries a pointer to one bit in a list the realm publishes. The API fetches the list,
signed and good for a minute, and reads the bit: set means revoked.

Use it for APIs that verify tokens offline and can't call the realm on each request, where five minutes of a
revoked token still working is too long. It's opt-in, per client or per API.

## Before you begin

- **Who can do it:** a realm administrator (a group holding `RealmOwner`) chooses which tokens carry an entry;
  `RealmViewer` can read the choice. Your API reads the lists without credentials: they are public.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** your API verifies tokens itself, against the realm's keys.

## How it works

The bit follows the same rules as [introspection](../introspection/). A revoked token or any token it was exchanged
from, a revoked family or session, a delegation given again, a scope no longer granted, an inactive client, or a
user or agent who no longer stands (a killed agent among them) all set it.

**1. A listed access token carries its entry** in a `status` claim:

```json
{
  "status": {
    "status_list": { "idx": 48213, "uri": "https://foobar.cvyuh.com/oauth2/status/<YYYY-MM-DD>" }
  }
}
```

`uri` names the list, and `idx` the token's place in it.

**2. The API fetches the list** at that `uri`:

```sh
curl 'https://foobar.cvyuh.com/oauth2/status/<YYYY-MM-DD>'
```

The answer, of type `application/statuslist+jwt`, is a JWT of type `statuslist+jwt`, signed by the realm with the
same algorithm as its access tokens. Verify it with the realm's published keys, as you verify its access tokens. Its
claims:

```json
{
  "sub": "https://foobar.cvyuh.com/oauth2/status/<YYYY-MM-DD>",
  "iat": <unix time>,
  "exp": <iat + 60>,
  "ttl": 60,
  "status_list": { "bits": 1, "lst": "eAEBAEC__wAAAA…" }
}
```

**3. The API reads the bit.** `lst` is base64url of the list, compressed in the ZLIB format. Each entry is one bit:
entry `idx` is bit `idx % 8` of byte `idx / 8`, counting from the least significant bit. `1` means the token is
revoked. Fetch the list again once its `ttl` (60 seconds) has passed.

## Set it up

Choose which tokens carry an entry: per client with
`statusListed` on the client (`https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client`; see [Call the API](../../../../develop/api/)), or per API with the realm's
`statusListedResources` (`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings`).

| Where | Setting | What it does |
|---|---|---|
| Client | `statusListed` | Every access token this client gets carries an entry (default off) |
| Realm | `statusListedResources` | Every access token for these APIs carries an entry, whichever client asked (empty by default) |

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `statusListed` on a client | off | on or off |
| `statusListedResources` | none | absolute URIs |
| A list's `ttl` | 60 seconds | fixed |
| Entries in one day's list | 131,072 | fixed |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Tokens carry no `status` claim | Neither the client nor the API is opted in | Set `statusListed`, or add the API to `statusListedResources` |
| A revoked token still passes for up to a minute | Your API's copy of the list is within its `ttl` | Expected; introspect for an answer at once |
| `server_error` on token requests for a listed client | The day's list is full | Narrow which tokens are listed; contact support if it recurs |

## Audit record

Reading a list writes no record. The revocation that sets a bit is a `TOKEN_REVOKED` record
([Revoke tokens](../revocation/)).

## Good to know

- **Opt-in.** Only tokens for clients or APIs you choose carry an entry. Every other token stays as it is.
- **Each token gets an entry of its own**, never shared, so revoking one never marks another.
- **One list per day.** A token's entry is in the list of the UTC day it was issued, named `YYYY-MM-DD`. Any other
  name is answered `404`.
- **A day's list holds 131,072 entries.** Keep status lists to the clients and APIs that need them: when a day's
  list runs out of room, a listed client's token request fails with `server_error` until the next UTC day.
- **The lists are public.** Any site may fetch them, from a browser too.

## Related

- [Revoke a token](../../../../gateway/guides/revoke-a-token/): the task, start to finish.
- [Revoke tokens](../revocation/): every way a token is revoked.
- [Introspection](../introspection/): ask the realm about a token instead.
- [Send signals](../../../signals/shared-signals/): tell other systems about security events.
