|
| 1 | +--- |
| 2 | +title: Use wildcard group role patterns |
| 3 | +description: Learn how to grant Azure Web PubSub clients permissions to many groups using wildcard role patterns. |
| 4 | +author: kevinguo-ed |
| 5 | +ms.author: kevinguo |
| 6 | +ms.service: azure-web-pubsub |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 01/28/2026 |
| 9 | +ms.custom: |
| 10 | +--- |
| 11 | + |
| 12 | +# Use wildcard group role patterns |
| 13 | + |
| 14 | +Azure Web PubSub now supports wildcard pattern matching in client "group" roles so you can authorize a client for many related groups with a single role string. |
| 15 | + |
| 16 | +You can continue to use the existing literal roles: |
| 17 | + |
| 18 | +- `webpubsub.sendToGroup.{groupName}` |
| 19 | +- `webpubsub.joinLeaveGroup.{groupName}` |
| 20 | + |
| 21 | +But you can now also use the new pattern roles: |
| 22 | + |
| 23 | +- `webpubsub.sendToGroups.{pattern}` |
| 24 | +- `webpubsub.joinLeaveGroups.{pattern}` |
| 25 | + |
| 26 | +Where `{pattern}` follows the wildcard syntax below. |
| 27 | + |
| 28 | +## When to use pattern roles |
| 29 | + |
| 30 | +Use pattern roles when: |
| 31 | + |
| 32 | +- A user or device must access a large but bounded dynamic set of groups (for example: all groups for a specific tenant or project) |
| 33 | +- You want to keep access tokens small (avoid listing dozens or hundreds of explicit group roles) |
| 34 | + |
| 35 | +## Pattern syntax |
| 36 | + |
| 37 | +| Symbol | Meaning | |
| 38 | +| ------ | ------- | |
| 39 | +| `?` | Matches exactly one character except `.` | |
| 40 | +| `*` | Matches zero or more characters except `.` | |
| 41 | +| `**` | Matches zero or more characters including `.` (crosses segment boundaries) | |
| 42 | +| `\` | Escape character for `\`, `*`, `?` | |
| 43 | +| `.` | Acts as a hierarchy separator and is never matched by `?` or `*` (only by `**`). | |
| 44 | + |
| 45 | +Additional rules: |
| 46 | +- Up to five total `*` characters (including those forming `**`) are allowed in a single pattern. |
| 47 | + |
| 48 | +### Examples |
| 49 | + |
| 50 | +| Pattern | Matches | Does not match | |
| 51 | +| ------- | ------- | -------------- | |
| 52 | +| `chat-*` | `chat-1`, `chat-room` | `chat.1`, `xchat-1` | |
| 53 | +| `clientA.*` | `clientA.alpha`, `clientA.1` | `clientA.alpha.room1`, `clientB.alpha` | |
| 54 | +| `clientA.**` | `clientA.alpha`, `clientA.alpha.room1` | `clientB.anything` | |
| 55 | +| `clientA.rooms.?1` | `clientA.rooms.a1`, `clientA.rooms.11` | `clientA.rooms.1`, `clientA.rooms.a.1` | |
| 56 | +| `literal\*star` | `literal*star` | `literalXstar` | |
| 57 | + |
| 58 | +### Escaping |
| 59 | + |
| 60 | +Prefix `*`, `?`, or `\` with `\` to match the literal character. Example: `project\*123` matches only `project*123`. |
| 61 | + |
| 62 | +## Using pattern roles in code |
| 63 | + |
| 64 | +Add the pattern role to the `roles` collection when generating a client access token. The client then automatically has the implied permissions for matching groups. |
| 65 | + |
| 66 | +## Code samples |
| 67 | + |
| 68 | +# [JavaScript](#tab/javascript) |
| 69 | + |
| 70 | +```js |
| 71 | +const token = await serviceClient.getClientAccessToken({ |
| 72 | + roles: [ |
| 73 | + // Can send to all groups under clientA. |
| 74 | + 'webpubsub.sendToGroups.clientA.**', |
| 75 | + // Can join/leave any direct child group under public. |
| 76 | + 'webpubsub.joinLeaveGroups.public.*' |
| 77 | + ] |
| 78 | +}); |
| 79 | +``` |
| 80 | + |
| 81 | +# [C#](#tab/csharp) |
| 82 | + |
| 83 | +```csharp |
| 84 | +var url = service.GetClientAccessUri(roles: new [] { |
| 85 | + // Can send to all groups under clientA. |
| 86 | + "webpubsub.sendToGroups.clientA.**", |
| 87 | + // Can join/leave any direct child group under public. |
| 88 | + "webpubsub.joinLeaveGroups.public.*" |
| 89 | +}); |
| 90 | +``` |
| 91 | + |
| 92 | +# [Python](#tab/python) |
| 93 | + |
| 94 | +```python |
| 95 | +token = service.get_client_access_token(roles=[ |
| 96 | + # Can send to all groups under clientA. |
| 97 | + "webpubsub.sendToGroups.clientA.**", |
| 98 | + |
| 99 | + # Can join/leave any direct child group under public. |
| 100 | + "webpubsub.joinLeaveGroups.public.*" |
| 101 | +]) |
| 102 | +``` |
| 103 | + |
| 104 | +# [Java](#tab/java) |
| 105 | + |
| 106 | +```java |
| 107 | +GetClientAccessTokenOptions opt = new GetClientAccessTokenOptions(); |
| 108 | +// Can send to all groups under clientA. |
| 109 | +opt.addRole("webpubsub.sendToGroups.clientA.**"); |
| 110 | + |
| 111 | +// Can join/leave any direct child group under public. |
| 112 | +opt.addRole("webpubsub.joinLeaveGroups.public.*"); |
| 113 | +WebPubSubClientAccessToken token = service.getClientAccessToken(opt); |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## Security guidance |
| 119 | + |
| 120 | +- Prefer the narrowest pattern that satisfies the scenario. |
| 121 | +- Minimize the use of `*` to reduce over-permissioning risks. |
| 122 | + |
| 123 | +## Frequently asked questions |
| 124 | + |
| 125 | +**Q: Can I mix literal and pattern roles?** |
| 126 | + |
| 127 | +Yes. A literal role always applies exactly; patterns add broader coverage. |
| 128 | + |
| 129 | + |
| 130 | +## Next steps |
| 131 | + |
| 132 | +> [!div class="nextstepaction"] |
| 133 | +> [Generate client access URL and use roles](howto-generate-client-access-url.md) |
0 commit comments