Token revocation
Deleting a token on the client's side changes nothing at the authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate.. This lesson follows the printer as it tells the photo service it has finished with its access, shows which copies of that access stop working and which carry on until they expire, and compares the printer revoking its tokens with Ava removing the connection herself.
Telling the server you are done
The calendar has arrived, and Ava would rather the printer did not keep access to her photos for another year. On the printer's account page, she selects Disconnect photo account.
The printer could simply delete the tokens it stored. Ava would see the connection disappear, but nothing would change at the photo service. The grant would still exist, and a copy of the refresh token anywhere else, in an old backup or in a thief's hands, would still work. Disconnecting properly means telling the authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. server that the printer has finished with its access.
The printer sends its refresh token to the photo service's revocation endpoint, defined in RFC 7009, authenticating exactly as it does at the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect.. All domains, credentials, and tokens in these examples are fictional.
POST /revoke HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tcHJpbnRlcjpkZW1vLW9ubHktbm90LWEtcmVhbC1zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
token=demo-refresh-token-4
&token_type_hint=refresh_tokenThe body names the token and, optionally, hints at its type, which helps the server look it up, as token_type_hint did at the introspectionA way for an API to ask the authorization server what a token means: whether it is still active and what access it carries. APIs need it when a token is a random string that only the authorization server can interpret. endpoint. The printer sends its refresh token because that is the credential that keeps the connection alive. The server checks that the token was issued to the client making the request, then invalidates it at once. A public clientAn OAuth client, such as code running in a browser or an app on a phone, that cannot keep a credential secret because the people using it can inspect it. It relies on protections such as PKCE instead of a client secret., which has no secret, may revoke its own tokens too, identifying itself by its client ID alone.
The answer carries nothing beyond its status:
HTTP/1.1 200 OKThe server returns 200 when it revoked the token, and also when the token was unknown, expired, or already revoked. That is not carelessness. The client wanted the token to stop working, and it has, so an error would give the client nothing useful to do. The same answer also tells a caller nothing about whether a random string was ever a token. And it makes the request safe to repeat: if the printer's first attempt times out, it sends the same request again without needing to know what happened to the first.
Real errors are few:
invalid_client, with 401: client authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. failed, as it would at the token endpoint.unauthorized_client: the token is a valid one issued to a different client. One client may not end another's access, so the server refuses rather than revoking, and the caller learns that it cannot do this.unsupported_token_type: the server does not revoke that kind of token, which can happen when a client tries to revoke an access token at a server that only revokes refresh tokens.- 503 Service Unavailable: the server could not handle the request right now, and the client must assume the token still works and try again later.
That last case shapes the order of the printer's own work. It marks the connection as disconnected straight away and stops using its tokens. It keeps the refresh token only in a queue of pending revocations and deletes it once the server has answered 200. Deleting first would leave a working token at the photo service and no way left to revoke it.
What revocation reaches
Revoking the refresh token ends the printer's ability to obtain new access tokens. What happens to access tokens already issued depends on the server and on the token format.
When a refresh token is revoked and the server supports revoking access tokens, the specification says it should also invalidate the access tokens issued under the same grant. The reverse is weaker. Revoking an access token may leave the refresh token working, and the server is only permitted, not required, to revoke that too. A client that wants to end everything sends the refresh token, and it can send its current access token as well, which does no harm.
Even then, revocation only reaches tokens that someone checks. Suppose the printer's newest access token was issued at 09:00 with a ten-minute lifetime, and the printer revokes its refresh token at 09:04. At 09:06, each of its tokens meets a different fate:
- The refresh token is refused at the token endpoint from that moment, because the authorization server that revoked it is the one that checks it.
- A reference access token is reported as inactive by introspection at once. An APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. that caches answers accepts it until its cached answer expires, the window Token introspection measured.
- A JWT access token validated locally is still accepted until its
exp, because the API never asks the authorization server. This one keeps working until 09:10.
At the token endpoint
- Who checks
- The authorization server
- Learns of it
- From that moment
Refused at the token endpoint
At an API that introspects
- Who checks
- The authorization server
- Learns of it
- When its cached answer expires
Reported as inactive by introspection
At an API that validates locally
- Who checks
- The API alone
- Learns of it
- Never
Still accepted until 09:10
Short lifetimes keep that window small.
The last case is the cost of local validation that Token formats and validation described. Short lifetimes keep that window small. For operations where six minutes is too long, such as deleting photos, an API can introspect even JWT access tokens before acting, trading a round trip for a current answer.
Nothing reaches backwards past the API either. Photos the printer downloaded before Ava disconnected are copies in its own systems. As the Trust boundaries lesson pointed out, stopping future requests cannot make those copies disappear.
Two ways to disconnect
So far, the printer started the revocation. Ava can also end the connection from the other side, on the photo service's list of connected applications, and the two are not the same.
When the printer revokes, the client is declaring that it no longer needs its tokens. It might do this because Ava asked, because she closed her printer account, or because it suspects its own token storage has been exposed and wants every token it holds to stop working. Revocation by the client starts from a token the client still has and can name. What else ends with it, such as the access tokens of the same grant or the grant itself, is up to the authorization server's policy.
When Ava removes the connection at the photo service, the authorization server ends the grant itself, along with every token family under it, and forgets that she approved the printer, so a new connection asks for her approval again. That works even when the printer is offline, broken, or no longer trustworthy, which is exactly when Ava most wants it. The printer is not told. It finds out the next time it uses its tokens: an API that checks with the photo service answers invalid_token, and the next refresh fails with invalid_grant. The refresh token grant lesson described the right response, marking the connection as needing attention and inviting Ava to reconnect if she wants the calendar back.
The photo service has one more lever, for when the printer itself can no longer be trusted. Suspending the client photo-printer stops it obtaining tokens for anyone, and, as Refresh tokens and rotation listed, ends every family issued to it. Its next request at the token endpoint fails client authentication with invalid_client.
A well-behaved client does both of its jobs. It revokes when its own reasons say so, and it accepts gracefully that someone else may end its access first.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Disconnect the printer and measure what stops workingRevoke tokens as the printer, see one client refused when it revokes another's token, measure what still works at each kind of API, then let Ava disconnect the printer herself.