Skip to content

Commit 2a93f2c

Browse files
authored
Merge pull request #306932 from Y-Sindo/main
[WebPubSub]Add wildcard group permission
2 parents 33df589 + 6b25769 commit 2a93f2c

9 files changed

Lines changed: 236 additions & 89 deletions

articles/azure-functions/functions-bindings-web-pubsub.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Azure Functions Web PubSub bindings
33
description: Understand how to use Web PubSub bindings with Azure Functions.
44
ms.topic: reference
55
ms.custom: devx-track-extended-java, devx-track-js, devx-track-python
6-
ms.date: 1/21/2026
6+
ms.date: 01/28/2026
77
zone_pivot_groups: programming-languages-set-functions-lang-workers
88
---
99

articles/azure-web-pubsub/concept-client-protocols.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ description: This article presents an overview of the client protocols for Azure
44
author: vicancy
55
ms.author: lianwei
66
ms.service: azure-web-pubsub
7-
ms.topic: reference
8-
ms.date: 11/08/2021
7+
ms.topic: conceptual
8+
ms.date: 03/30/2026
99
ms.custom: sfi-ropc-nochange
1010
---
1111

@@ -42,13 +42,13 @@ You could also configure properties for the client connection when generating th
4242

4343
You could also add custom claims into the access token, and these values are preserved as the `claims` property in [connect upstream request body](./reference-cloud-events.md#system-connect-event).
4444

45-
[Server SDKs](./howto-generate-client-access-url.md#generate-from-service-sdk) provides APIs to generate the access token for the clients.
45+
[Server SDKs](./howto-generate-client-access-url.md#generate-from-service-sdk) provides APIs to generate the access token for the clients.
4646

4747
<a name="simple_client"></a>
4848

4949
## The simple WebSocket client
5050

51-
A **simple WebSocket client**, as the naming indicates, is a simple WebSocket connection. It can also have its own custom subprotocol.
51+
A **simple WebSocket client**, as the naming indicates, is a simple WebSocket connection. It can also have its own custom subprotocol.
5252

5353
For example, in JavaScript, you can create a simple WebSocket client by using the following code:
5454

@@ -62,7 +62,7 @@ var client2 = new WebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', '
6262

6363
Simple WebSocket client has two modes: `sendEvent` and `sendToGroup`. The mode is determined once the connection is established and cannot be changed later.
6464

65-
`sendEvent` is the default mode for the simple WebSocket client. In `sendEvent` mode, every WebSocket frame the client sent is considered as a `message` event. Users can configure [event handlers](./concept-service-internals.md#event-handler) or [event listeners](./concept-service-internals.md#event-listener) to handle these `message` events.
65+
`sendEvent` is the default mode for the simple WebSocket client. In `sendEvent` mode, every WebSocket frame the client sent is considered as a `message` event. Users can configure [event handlers](./concept-service-internals.md#event-handler) or [event listeners](./concept-service-internals.md#event-listener) to handle these `message` events.
6666

6767
```javascript
6868
// Every data frame is considered as a `message` event
@@ -102,7 +102,7 @@ var pubsubClient = new WebSocket('wss://test.webpubsub.azure.com/client/hubs/hub
102102

103103
```js
104104
let ackId = 0;
105-
pubsubClient.send(
105+
pubsubClient.send(
106106
JSON.stringify({
107107
type: 'joinGroup',
108108
group: 'group1',
@@ -114,7 +114,7 @@ pubsubClient.send(
114114

115115
```js
116116
let ackId = 0;
117-
pubsubClient.send(
117+
pubsubClient.send(
118118
JSON.stringify({
119119
type: 'sendToGroup',
120120
group: 'group1',
@@ -191,6 +191,8 @@ As you likely noticed in the earlier PubSub WebSocket client description, a clie
191191
| `webpubsub.sendToGroup` | The client can publish messages to any group. |
192192
| `webpubsub.joinLeaveGroup.<group>` | The client can join or leave group `<group>`. |
193193
| `webpubsub.sendToGroup.<group>` | The client can publish messages to group `<group>`. |
194+
| `webpubsub.joinLeaveGroups.<pattern>` | The client can join/leave any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
195+
| `webpubsub.sendToGroups.<pattern>` | The client can publish messages to any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
194196
| | |
195197

196198
The permission of a client can be granted in several ways:
@@ -199,7 +201,7 @@ The permission of a client can be granted in several ways:
199201

200202
Client can connect to the service using a JWT. The token payload can carry information such as the `role` of the client. When signing the JWT to the client, you can grant permissions to the client by giving the client specific roles.
201203

202-
For example, let's sign a JWT that has the permission to send messages to `group1` and `group2`:
204+
For example, let's sign a JWT that has the permission to send messages to `group1` and `group2`:
203205

204206
```js
205207
let token = await serviceClient.getClientAccessToken({
@@ -231,6 +233,10 @@ let service = new WebPubSubServiceClient("<your_connection_string>", "test-hub")
231233
await service.grantPermission("<connection_id>", "joinLeaveGroup", { targetName: "group1" });
232234
```
233235

236+
> [!NOTE]
237+
> Assigning wildcard roles (e.g., `webpubsub.sendToGroups.<pattern>`) through REST APIs or server SDKs are not supported yet. This feature will be supported in a future update.
238+
239+
234240
## Next steps
235241

236242
[!INCLUDE [next step](includes/include-next-step.md)]

articles/azure-web-pubsub/concept-service-internals.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ A client can publish to other clients only when it's _authorized_ to. The `role`
212212
| `webpubsub.sendToGroup` | The client can publish messages to any group. |
213213
| `webpubsub.joinLeaveGroup.<group>` | The client can join/leave group `<group>`. |
214214
| `webpubsub.sendToGroup.<group>` | The client can publish messages to group `<group>`. |
215+
| `webpubsub.joinLeaveGroups.<pattern>` | The client can join/leave any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
216+
| `webpubsub.sendToGroups.<pattern>` | The client can publish messages to any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
215217
216218
The server-side can also grant or revoke permissions of the client dynamically through [server protocol](#connection-manager) as to be illustrated in a later section.
217219
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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)

articles/azure-web-pubsub/howto-connect-mqtt-websocket-client.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ A client can publish to other clients only when it's *authorized* to do so. A cl
4343
| `webpubsub.sendToGroup` | The client can publish messages to any group. |
4444
| `webpubsub.joinLeaveGroup.<group>` | The client can join or leave group `<group>`. |
4545
| `webpubsub.sendToGroup.<group>` | The client can publish messages to group `<group>`. |
46+
| `webpubsub.joinLeaveGroups.<pattern>` | The client can join/leave any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
47+
| `webpubsub.sendToGroups.<pattern>` | The client can publish messages to any group whose name matches `<pattern>` (see [Wildcard group role patterns](./concept-wildcard-group-roles.md)). |
4648
| | |
4749

4850
## Authentication and authorization

0 commit comments

Comments
 (0)