Skip to content

Commit 64c68e5

Browse files
authored
Merge pull request #2289 from rabbitmq/add-var-expansion
Add var expansion on scopes to oauth2 examples
2 parents f9e3ab1 + 8274514 commit 64c68e5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

docs/oauth2-examples/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The guide is accompanied by [a public GitHub repository](https://github.com/rabb
5757
* [Using a custom scope field](#using-custom-scope-field)
5858
* [Using multiple asymmetrical signing keys](#using-multiple-asymmetrical-signing-keys)
5959
* [Using scope aliases](#using-scope-aliases)
60+
* [Using variable expansion in scopes](#using-var-expansion)
6061
* [Preferred username claims](#preferred-username-claims)
6162
* [Using Rich Authorization Requests tokens](#use-rar-tokens)
6263

@@ -699,6 +700,27 @@ make stop-perftest-producer PRODUCER=producer_with_roles
699700
make stop-perftest-consumer CONSUMER=consumer_with_roles
700701
```
701702

703+
### Using variable expansion in scopes {#using-var-expansion}
704+
705+
There are times when it is convenient to define a scope that uses a variable in either:
706+
707+
* The vhost part of the scope
708+
* The resource and/or in the routing key part
709+
710+
The variable name can be `vhost`, whose value matches the vhost you are accessing, or any single
711+
value claim in the token, such as `user_name`.
712+
713+
To demonstrate this feature:
714+
715+
1. Start Keycloak Oauth provider and RabbitMQ by following the steps in
716+
[Keycloak](./oauth2-examples-keycloak). Keycloak is already configured to issue tokens with the
717+
scope `rabbitmq.configure:*/q-{user_name}`.
718+
2. Log in to the management UI at `http://localhost:15672` with the user name `rabbit_admin`.
719+
3. Try to create a queue with the name `test`. Expect the effort to fail with an authorization error.
720+
4. Create a queue with the name `q-rabbit_admin`. Expect to be allowed to do this.
721+
722+
There is no configuration required in RabbitMQ, but RabbitMQ 4.1.1 is required.
723+
702724
### Preferred username claims {#preferred-username-claims}
703725

704726
RabbitMQ needs to figure out the username associated to the token so that it can display it in the Management UI.

versioned_docs/version-4.1/oauth2-examples/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The guide is accompanied by [a public GitHub repository](https://github.com/rabb
5757
* [Using a custom scope field](#using-custom-scope-field)
5858
* [Using multiple asymmetrical signing keys](#using-multiple-asymmetrical-signing-keys)
5959
* [Using scope aliases](#using-scope-aliases)
60+
* [Using variable expansion in scopes](#using-var-expansion)
6061
* [Preferred username claims](#preferred-username-claims)
6162
* [Using Rich Authorization Requests tokens](#use-rar-tokens)
6263

@@ -699,6 +700,27 @@ make stop-perftest-producer PRODUCER=producer_with_roles
699700
make stop-perftest-consumer CONSUMER=consumer_with_roles
700701
```
701702

703+
### Using variable expansion in scopes {#using-var-expansion}
704+
705+
There are times when it is convenient to define a scope that uses a variable in either:
706+
707+
* The vhost part of the scope
708+
* The resource and/or in the routing key part
709+
710+
The variable name can be `vhost`, whose value matches the vhost you are accessing, or any single
711+
value claim in the token, such as `user_name`.
712+
713+
To demonstrate this feature:
714+
715+
1. Start Keycloak Oauth provider and RabbitMQ by following the steps in
716+
[Keycloak](./oauth2-examples-keycloak). Keycloak is already configured to issue tokens with the
717+
scope `rabbitmq.configure:*/q-{user_name}`.
718+
2. Log in to the management UI at `http://localhost:15672` with the user name `rabbit_admin`.
719+
3. Try to create a queue with the name `test`. Expect the effort to fail with an authorization error.
720+
4. Create a queue with the name `q-rabbit_admin`. Expect to be allowed to do this.
721+
722+
There is no configuration required in RabbitMQ, but RabbitMQ 4.1.1 is required.
723+
702724
### Preferred username claims {#preferred-username-claims}
703725

704726
RabbitMQ needs to figure out the username associated to the token so that it can display it in the Management UI.

0 commit comments

Comments
 (0)