Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Token revocation

Deleting a token on the client's side changes nothing at the authorization server. 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 authorization 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 endpoint. 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_token

The body names the token and, optionally, hints at its type, which helps the server look it up, as token_type_hint did at the introspection 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 client, 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 OK

The 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 authentication 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 API 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.

After the printer revokes at 09:04, only the tokens that someone checks with the authorization server stop working at once.

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.

Ava disconnects her photo account, and the printer's revocation request times out. What should the printer do with its stored refresh token? 1 of 3

Choose one answer.

The printer revokes its refresh token at 09:04. Its latest access token is a JWT that expires at 09:10, and the photo API validates JWTs locally. What happens if that access token is used at 09:06? 2 of 3

Choose one answer.

The printer's servers have been broken for a week, and Ava wants the printer to lose access to her photos before it comes back. What should she do? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity