Skip to content

Commit 334f45d

Browse files
Add var expansion example
1 parent f9e3ab1 commit 334f45d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/oauth2-examples/index.md

Lines changed: 19 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,24 @@ 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 which uses a variable
706+
in either the vhost part of the scope, or in the resource and/or in the routing
707+
key part. The variable name can be `vhost`, whose value matches the vhost you
708+
are accessing, or any single value claim in the token such as `user_name`.
709+
710+
To demonstrate this feature, follow these steps:
711+
712+
1. Follow the steps explained to demonstrate [Keycloak](./oauth2-examples-keycloak)
713+
Oauth provider.
714+
2. Keycloak is configured to issue tokens with the scope `rabbitmq.configure:*/q-{user_name}`
715+
3. Log in with the username `rabbit_admin`
716+
4. Try to create a queue with the name `test`. It should fail with an authorization error
717+
5. Try to create a queue with the name `q-rabbit_admin`. It should allow you.
718+
719+
There is no configuration required in RabbitMQ. But at least it requires RabbitMQ 4.1.1.
720+
702721
### Preferred username claims {#preferred-username-claims}
703722

704723
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: 19 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,24 @@ 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 which uses a variable
706+
in either the vhost part of the scope, or in the resource and/or in the routing
707+
key part. The variable name can be `vhost`, whose value matches the vhost you
708+
are accessing, or any single value claim in the token such as `user_name`.
709+
710+
To demonstrate this feature, follow these steps:
711+
712+
1. Follow the steps explained to demonstrate [Keycloak](./oauth2-examples-keycloak)
713+
Oauth provider.
714+
2. Keycloak is configured to issue tokens with the scope `rabbitmq.configure:*/q-{user_name}`
715+
3. Log in with the username `rabbit_admin`
716+
4. Try to create a queue with the name `test`. It should fail with an authorization error
717+
5. Try to create a queue with the name `q-rabbit_admin`. It should allow you.
718+
719+
There is no configuration required in RabbitMQ. But at least it requires RabbitMQ 4.1.1.
720+
702721
### Preferred username claims {#preferred-username-claims}
703722

704723
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)