Skip to content
GatewayMarkdown

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.

APIRFC 7009

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). The examples use the app app.example.com with the client id web-app, and the user maya.

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

    Terminal window
    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.

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.

Revoke as much as the leak warrants:

  1. Everything one client holds: set it inactive.

    Terminal window
    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.

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

    Terminal window
    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" }'
Where the token is checkedRefused
The realm: userinfo, exchange, refreshAt once
IntrospectionAt once
The gatewayAt its next revocation poll (every 10 seconds by default)
An API checking signatures with a status listAt its next list fetch (lists are good for a minute)
An API checking signatures onlyWhen the token expires (five minutes by default)

Every revocation is on the audit trail as TOKEN_REVOKED: see What is recorded.

For APIs that check signatures, list their tokens on status lists:

  • One client’s tokens: set statusListed on the client.

    Terminal window
    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.

    Terminal window
    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"] }'

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.