# Revocation feed

> Every live revocation in the realm, in one feed your own enforcement point polls, so a decision made without the realm still refuses what the realm has revoked.

An enforcement point that decides locally ([Decide locally](/gateway/decisions/decide-locally/)) never asks the realm about a token, so it
needs another way to learn what the realm has revoked. The revocation feed is that way: one answer listing every
revoked token, session and principal that could still verify. The [gateway](/gateway/) polls it every ten
seconds; your own enforcement point can do the same. The feed is available today, with or without the gateway.

## Before you begin

- **A client for your enforcement point** with the scope `revocations:read`: registering it takes a realm
  administrator in a group holding `RealmOwner`, with the API.
- **An enforcement point of your own** that verifies tokens and can hold the feed between polls.

## How it works

`GET /policies/v1/revocations`, with a token carrying the scope `revocations:read` for the resource
`https://foobar.cvyuh.com/policies/v1`, answers every list, each present whether empty or not:

| List | Refuse a token when |
|---|---|
| `tokens` | Its `jti`, or the `jti` of any token it was exchanged from, is listed |
| `families` | Its refresh `family` is listed |
| `sessions` | The session it names (`sid`) is listed |
| `subjects` | Its `sub`, or any actor in its `act`, is listed: a stopped agent, every agent beneath it, or a user no longer active |
| `subjectsBefore` | Its `sub` or an actor is listed and the token was issued at or before `notBeforeMs` |
| `grants` | Its `sub` and `client_id` are a listed pair, and it was issued at or before `notBeforeMs`: the user took back that app |
| `delegations` | Its `sub` is listed, its `act` names the listed agent at any depth, and it was issued at or before `notBeforeMs`: the user took back that agent |

Each entry is an object: `{ "jti": … }`, `{ "family": … }`, `{ "sid": … }`, `{ "sub": … }`, and for the timed lists
`{ "sub": …, "notBeforeMs": … }`, with `clientId` or `agent` beside them. `notBeforeMs` is in milliseconds since the
epoch.

Every entry stays listed for as long as a token it covers could still verify, then drops off. So every poll returns
the whole feed, and a missed poll loses nothing. The answer carries an entity tag: send `If-None-Match`, and an
unchanged feed is a `304`.

## Set it up

1. **Register your enforcement point** as a client with the `client_credentials` grant and the scope
   `revocations:read`, with `https://foobar.cvyuh.com/policies/v1` in its `allowedResources`: the call is on
   [Decide locally](/gateway/decisions/decide-locally/#set-it-up).
2. **Poll the feed** with its token, more often than you poll policies, and check every token against every list:

   ```sh
   curl -i https://foobar.cvyuh.com/policies/v1/revocations \
     -H "Authorization: Bearer $TOKEN" \
     -H 'If-None-Match: "<the last ETag>"'
   ```

   ```json
   { "tokens": [], "families": [], "sessions": [], "subjects": [{ "sub": "<agent id>" }],
     "subjectsBefore": [], "grants": [], "delegations": [] }
   ```

3. **Keep the last good copy** when a poll fails, and refuse everything once polls have failed for long enough, as the
   gateway does: see [Fails closed](/gateway/protect-apis/run-the-gateway/#fails-closed).

## Good to know

- **Check the whole chain.** Check the token's `sub` and every actor in its `act`, and every token it was exchanged
  from, not just the outermost.
- **Clients aren't listed:** see
  [A client you set inactive](/gateway/revocation/what-can-be-revoked/#a-client-you-set-inactive).

## Limits and defaults

| What | Value |
|---|---|
| How long an entry stays listed | While a token it covers could still verify |
| A changed feed | A new `ETag`; an unchanged one is `304` |
| The token to read it | Audience `https://foobar.cvyuh.com/policies/v1`, scope `revocations:read` |

## What your enforcement point sees when it fails

| Status | Why | What to do |
|---|---|---|
| `401` | The token is missing, expired or for another audience | Get a new token for `https://foobar.cvyuh.com/policies/v1` |
| `403` | The token lacks `revocations:read` | Add the scope to the client |
| `5xx`, or no answer | The realm couldn't answer | Keep the last good copy, and refuse once it's too old |

## Audit record

Reading the feed writes no record. Each revocation it lists was recorded when it was made: see
[Audit record](/gateway/revocation/what-can-be-revoked/#audit-record).

## Related

- [Decide locally](/gateway/decisions/decide-locally/): the rest of what a local enforcement point does.
- [What can be revoked](/gateway/revocation/what-can-be-revoked/): what puts each entry in the feed.
- [How fast revocation takes effect](/gateway/revocation/how-fast/): the feed beside the other ways to check.
