Skip to content

Commit 072464d

Browse files
Explain keycloak jwt token formats
1 parent dc7b212 commit 072464d

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

docs/oauth2-examples-keycloak.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,66 @@ and Keycloak as Authorization Server using the following flows:
2828
* Access management HTTP API
2929
* Application authentication and authorization
3030

31+
## Keycloak JWT payloads
32+
33+
Keycloak may issue two types of JWT payloads.
34+
35+
One type of payload is found in a [Requesting Party Token](./oauth2#requesting-party-token).
36+
RabbitMQ supports this type of token and it extracts the scopes from it.
37+
You do not need to configure anything.
38+
39+
A second type of payload is the following. The claim `roles` is not strictily
40+
speaking part of Keycloak official claims. Instead, it is a custom claim configured
41+
by the user via the Keycloak administration console.
42+
43+
```json
44+
{
45+
"realm_access": {
46+
"roles": [
47+
"offline_access",
48+
"uma_authorization",
49+
"rabbitmq.tag:management",
50+
]
51+
},
52+
"resource_access": {
53+
"account": {
54+
"roles": [
55+
"manage-account",
56+
"manage-account-links",
57+
"view-profile",
58+
"rabbitmq.write:*/*"
59+
]
60+
}
61+
},
62+
"roles": "rabbitmq.read:*/*",
63+
"scope": "profile email"
64+
}
65+
```
66+
67+
RabbitMQ does not read the scopes from this token unless you configure it to do so.
68+
For instance, to configure RabbitMQ to extract the scopes from "roles" under "realm_access",
69+
you add the following configuration variable:
70+
71+
```json
72+
auth_oauth2.additional_scopes_key = realm_access.roles
73+
```
74+
75+
To configure RabbitMQ to also read from "resource_access", you modify the previous
76+
configuration as follows:
77+
78+
```json
79+
auth_oauth2.additional_scopes_key = realm_access.roles resource_access.account.roles
80+
```
81+
82+
And finally, if you also want to use the scopes in the claim `roles`, you modify
83+
the previous configuration:
84+
85+
```json
86+
auth_oauth2.additional_scopes_key = roles realm_access.roles resource_access.account.roles
87+
```
88+
89+
RabbitMQ reads the scopes from all those sources.
90+
3191
## Prerequisites to follow this guide
3292

3393
* Docker

docs/oauth2.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ There's also a companion [troubleshooting guide for OAuth 2-specific problems](.
4747
* [Preferred username claims](#preferred-username-claims)
4848
* [Discovery Endpoint params](#discovery-endpoint-params)
4949
* [Rich Authorization Request](#rich-authorization-request)
50+
* [Requesting Party Token](#requesting-party-token)
5051

5152
### [Advanced usage](#advanced-usage)
5253

@@ -719,6 +720,54 @@ This is the URL built to access the OpenId Discovery endpoint:
719720
https://myissuer.com/v2/.well-known/authorization-server?param1=value1&param2=value2
720721
```
721722
723+
### Requesting Party Token {#requesting-party-token}
724+
725+
A **Requesting Party Token (RPT)** is a special OAuth 2.0 **access token**
726+
issued by an **Authorization Server** in the [User-Managed Access (UMA) 2.0](https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html) framework.
727+
It is used by a **Requesting Party** (such as an application or user) to access
728+
a protected resource on a Resource Server like RabbitMQ, after being authorized
729+
based on a resource owner policies.
730+
731+
[Keycloak](./oauth2-examples-keycloak) is one of the Authorization Servers that issues this type of tokens.
732+
An RPT is typically a JWT with permissions claims under a claim called `authorization`.
733+
See the example below. The rest of the claims have been removed from the token for
734+
brevity:
735+
736+
```json
737+
{
738+
"authorization": {
739+
"permissions": [
740+
{
741+
"scopes": [
742+
"rabbitmq-resource.read:*/*"
743+
],
744+
"rsid": "2c390fe4-02ad-41c7-98a2-cebb8c60ccf1",
745+
"rsname": "allvhost"
746+
},
747+
{
748+
"scopes": [
749+
"rabbitmq-resource:vhost1/*"
750+
],
751+
"rsid": "e7f12e94-4c34-43d8-b2b1-c516af644cee",
752+
"rsname": "vhost1"
753+
},
754+
{
755+
"rsid": "12ac3d1c-28c2-4521-8e33-0952eff10bd9",
756+
"scopes": [
757+
"rabbitmq-resource.tag:administrator"
758+
]
759+
}
760+
]
761+
},
762+
"scope": "email profile",
763+
}
764+
```
765+
766+
RabbitMQ supports this token format. It reads all the scopes in all the `permissions`
767+
claims. If the token also contains the standard `scope` claim, RabbitMQ adds it to the
768+
list of scopes presented by the token.
769+
770+
722771
### Rich Authorization Request {#rich-authorization-request}
723772
724773
The [Rich Authorization Request](https://oauth.net/2/rich-authorization-requests/) extension provides a way for

0 commit comments

Comments
 (0)