|
| 1 | +# MSC4254: Usage of [RFC7009] Token Revocation for Matrix client logout |
| 2 | + |
| 3 | +This proposal is part of the broader [MSC3861: Next-generation auth for Matrix, based on OAuth 2.0/OIDC][MSC3861]. |
| 4 | + |
| 5 | +This MSC specifies how Matrix clients should use OAuth 2.0 Token Revocation as defined in [RFC7009] to implement client logout. |
| 6 | + |
| 7 | +## Proposal |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +This proposal requires the client to know the following authorization server metadata about the homeserver: |
| 12 | + |
| 13 | +- `revocation_endpoint`: the URL where the client is able to revoke tokens |
| 14 | + |
| 15 | +The discovery of the above metadata is out of scope for this MSC, and is currently covered by [MSC2965]. |
| 16 | + |
| 17 | +### Token revocation |
| 18 | + |
| 19 | +When a user wants to log out from a client, the client should revoke either its access token or refresh token by making a POST request to the revocation endpoint as described in [RFC7009]. |
| 20 | + |
| 21 | +The server must revoke both the access token and refresh token associated with the token provided in the request. |
| 22 | + |
| 23 | +The request includes: |
| 24 | +- The `token` parameter containing either the access token or refresh token to revoke |
| 25 | +- Optionally, the `token_type_hint` parameter, with either the `access_token` or `refresh_token` value. If provided, the server must use this value to determine which token to revoke |
| 26 | +- The `client_id` obtained during client registration |
| 27 | + |
| 28 | +#### Sample flow |
| 29 | + |
| 30 | +Revoking using the access token: |
| 31 | + |
| 32 | +```http |
| 33 | +POST /oauth2/revoke HTTP/1.1 |
| 34 | +Host: auth.example.com |
| 35 | +Content-Type: application/x-www-form-urlencoded |
| 36 | +
|
| 37 | +token=mat_ooreiPhei2wequu9fohkai3AeBaec9oo& |
| 38 | +token_type_hint=access_token& |
| 39 | +client_id=s6BhdRkqt3 |
| 40 | +``` |
| 41 | + |
| 42 | +```http |
| 43 | +HTTP/1.1 200 OK |
| 44 | +``` |
| 45 | + |
| 46 | +Or equivalently, using the refresh token: |
| 47 | + |
| 48 | +```http |
| 49 | +POST /oauth2/revoke HTTP/1.1 |
| 50 | +Host: auth.example.com |
| 51 | +Content-Type: application/x-www-form-urlencoded |
| 52 | +
|
| 53 | +token=mar_Pieyiev3aenahm4atah7aip3eiveizah& |
| 54 | +token_type_hint=refresh_token& |
| 55 | +client_id=s6BhdRkqt3 |
| 56 | +``` |
| 57 | + |
| 58 | +```http |
| 59 | +HTTP/1.1 200 OK |
| 60 | +``` |
| 61 | + |
| 62 | +### Handling errors |
| 63 | + |
| 64 | +The server may return an error response as defined in [RFC7009]. The client should handle these errors appropriately: |
| 65 | + |
| 66 | +- If the token is already revoked, the server returns a 200 OK response |
| 67 | +- If the client is not authorized to revoke the token, the server returns a 401 Unauthorized response |
| 68 | +- For other errors, the server returns a 400 Bad Request response with error details |
| 69 | + |
| 70 | +## Potential issues |
| 71 | + |
| 72 | +The main consideration around token revocation is ensuring proper cleanup of all related tokens and state. The server must: |
| 73 | + |
| 74 | +1. Track the relationship between access tokens and refresh tokens |
| 75 | +2. Properly revoke both tokens when either one is provided |
| 76 | +3. Clean up any Matrix device associated with the session |
| 77 | + |
| 78 | +## Alternatives |
| 79 | + |
| 80 | +### OpenID Connect RP-Initiated Logout |
| 81 | + |
| 82 | +OpenID Connect defines a [RP-Initiated Logout](https://openid.net/specs/openid-connect-rpinitiated-1_0.html) specification that allows clients to initiate a logout through a browser redirect. This would: |
| 83 | + |
| 84 | +1. Allow the server to clear browser session state |
| 85 | +2. Support single logout across multiple clients |
| 86 | +3. Give visual feedback to the user about the logout process |
| 87 | + |
| 88 | +However, this approach requires a browser redirect which may not be desirable for all clients, especially mobile platforms. |
| 89 | + |
| 90 | +## Security considerations |
| 91 | + |
| 92 | +Token revocation is a critical security feature that allows users to terminate access when needed. Some key security aspects: |
| 93 | + |
| 94 | +- Servers must revoke both the access token and refresh token when either is revoked |
| 95 | +- The server should consider revoking other related sessions, like browser cookie sessions used during authentication |
| 96 | +- Revoking a token should be effective immediately, and not be usable for any further requests |
| 97 | + |
| 98 | +[RFC7009]: https://tools.ietf.org/html/rfc7009 |
| 99 | +[MSC2965]: https://github.com/matrix-org/matrix-spec-proposals/pull/2965 |
| 100 | +[MSC3861]: https://github.com/matrix-org/matrix-spec-proposals/pull/3861 |
0 commit comments