# Revoke a token

> Revoke a token, a client's access or an agent's, when a user signs out or a token leaks, and know when each kind of API stops accepting it.

A token you no longer trust should stop working before it expires. An app revokes its own tokens when a user signs
out; a realm administrator revokes far more at once when a token leaks. Revoking a refresh token revokes every access
token issued under it too. This guide is for app developers signing users out cleanly, and for realm
administrators answering a leak.

**Before you start:** for an app, its client credentials; for a leak, a realm administrator's session in
`$CVYUH_SESSION`, in a group holding `RealmOwner` ([Call the API](/develop/api/)). The examples use the app `app.example.com` with the client id
`web-app`, and the user `maya`.

## As an app, at sign-out

<Steps>

1. Post the refresh token to the realm's revocation endpoint, authenticated as the client it was issued to:

   ```sh
   curl https://foobar.cvyuh.com/oauth2/revoke -u "web-app:<the secret>" \
     -d "token=<the token>" -d token_type_hint=refresh_token
   ```

2. The realm answers `200`. The token, its family and every access token issued under it are revoked.

</Steps>

An unknown or expired token is answered `200` too, so nothing can be learned from it. Only the client the token was
issued to may revoke it; another client is refused `unauthorized_client`.

## As a realm administrator, for a leak

Revoke as much as the leak warrants:

<Steps>

1. **Everything one client holds:** set it inactive.

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/web-app \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "status": "inactive" }'
   ```

2. **Everything an agent holds**, and every agent beneath it: quarantine or kill it, as in
   [Stop an agent](/workforce-identity/guides/agents/stop-an-agent/).

3. **Everything a user holds:** set them inactive. Their tokens read inactive everywhere until you set them `active`
   again.

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "status": "inactive" }'
   ```

</Steps>

<Aside type="caution" title="A client you set inactive">
  The gateway needs one more step to refuse a client's tokens before they expire: see
  [A client you set inactive](/gateway/revocation/what-can-be-revoked/#a-client-you-set-inactive).
</Aside>

## Check it worked

| Where the token is checked | Refused |
|---|---|
| The realm: userinfo, exchange, refresh | At once |
| Introspection | At once |
| The gateway | At its next revocation poll (every 10 seconds by default) |
| An API checking signatures with a status list | At its next list fetch (lists are good for a minute) |
| An API checking signatures only | When the token expires (five minutes by default) |

Every revocation is on the audit trail as `TOKEN_REVOKED`: see [What is recorded](/audit-reports/audit-trail/what-is-recorded/).

## Make offline checkers learn faster

For APIs that check signatures, list their tokens on [status lists](/workforce-identity/applications/revoke-access/status-lists/):

- One client's tokens: set `statusListed` on the client.

  ```sh
  curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/web-app \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "statusListed": true }'
  ```

- Every token for an API: name it in the realm's `oauth2Settings`.

  ```sh
  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 '{ "statusListedResources": ["https://erp.example.com/api"] }'
  ```

## Undo it

A revoked token can't be restored: the app signs the user in again. Set a client or user back to `active` to let them
get new tokens; an agent comes back from quarantine the same way, but a killed agent never does.

## Related

- [What can be revoked](/gateway/revocation/what-can-be-revoked/): every kind of revocation.
- [Revoke tokens](/workforce-identity/applications/revoke-access/revocation/): the call in full.
- [How fast revocation takes effect](/gateway/revocation/how-fast/): at each kind of API.
