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.
As an app, at sign-out
Section titled “As an app, at sign-out”-
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 -
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.
As a realm administrator, for a leak
Section titled “As a realm administrator, for a leak”Revoke as much as the leak warrants:
-
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" }' -
Everything an agent holds, and every agent beneath it: quarantine or kill it, as in Stop an agent.
-
Everything a user holds: set them inactive. Their tokens read inactive everywhere until you set them
activeagain.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" }'
Check it worked
Section titled “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.
Make offline checkers learn faster
Section titled “Make offline checkers learn faster”For APIs that check signatures, list their tokens on status lists:
-
One client’s tokens: set
statusListedon 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"] }'
Undo it
Section titled “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
Section titled “Related”- What can be revoked: every kind of revocation.
- Revoke tokens: the call in full.
- How fast revocation takes effect: at each kind of API.