Skip to content

Commit 631ffcb

Browse files
Merge pull request #267228 from vicancy/patch-12
Update the doc
2 parents dfdaf16 + 7723a51 commit 631ffcb

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,25 @@ The Web PubSub service provides two types of endpoints for clients to connect to
2323

2424
Clients connect to the service with a JSON Web Token (JWT). The token can be in either the query string, as `/client/?hub={hub}&access_token={token}`, or the `Authorization` header, as `Authorization: Bearer {token}`.
2525

26-
Here is a general authorization workflow:
26+
Here's a general authorization workflow:
2727

2828
1. The client negotiates with your application server. The application server contains the authorization middleware, which handles the client request and signs a JWT for the client to connect to the service.
2929
1. The application server returns the JWT and the service URL to the client.
30-
1. The client tries to connect to the Web PubSub service by using the URL and the JWT that's returned from the application server.
30+
1. The client tries to connect to the Web PubSub service by using the URL and the JWT token returned from the application server.
31+
32+
### Supported claims
33+
You could also configure properties for the client connection when generating the access token by specifying special claims inside the JWT token:
34+
35+
| Description | Claim type | Claim value | Notes |
36+
| --- | --- | --- | --- |
37+
| The `userId` for the client connection | `sub` | the userId | Only one `sub` claim is allowed. |
38+
| The lifetime of the token | `exp` | the expiration time | The `exp` (expiration time) claim identifies the expiration time on or after which the token MUST NOT be accepted for processing. |
39+
| The [permissions](#permissions) the client connection initially has | `role` | the role value defined in [permissions](#permissions) | Specify multiple `role` claims if the client has multiple permissions. |
40+
| The initial groups that the client connection joins once it connects to Azure Web PubSub | `group` | the group to join | Specify multiple `group` claims if the client joins multiple groups. |
41+
42+
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).
43+
44+
[Server SDKs](./howto-generate-client-access-url.md#generate-from-service-sdk) provides APIs to generate the access token for the clients.
3145

3246
<a name="simple_client"></a>
3347

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

4862
## The PubSub WebSocket client
4963

50-
A **PubSub WebSocket client**, is the WebSocket client using subprotocols defined by the Azure Web PubSub service:
64+
A **PubSub WebSocket client** is the WebSocket client using subprotocols defined by the Azure Web PubSub service:
5165

5266
* `json.webpubsub.azure.v1`
5367
* `protobuf.webpubsub.azure.v1`
@@ -112,13 +126,13 @@ The **PubSub WebSocket Client** supports `ackId` property for `joinGroup`, `leav
112126

113127
#### Behavior when No `ackId` specified
114128

115-
If `ackId` is not specified, it's fire-and-forget. Even there're errors when brokering messages, you have no way to get notified.
129+
If `ackId` isn't specified, it's fire-and-forget. Even there are errors when brokering messages, you have no way to get notified.
116130

117131
#### Behavior when `ackId` specified
118132

119133
##### Idempotent publish
120134

121-
`ackId` is a uint64 number and should be unique within a client with the same connection id. Web PubSub Service records the `ackId` and messages with the same `ackId` will be treated as the same message. The service refuses to broker the same message more than once, which is useful in retry to avoid duplicated messages. For example, if a client sends a message with `ackId=5` and fails to receive an ack response with `ackId=5`, then the client retries and sends the same message again. In some cases, the message is already brokered and the ack response is lost for some reason, the service will reject the retry and response an ack response with `Duplicate` reason.
135+
`ackId` is a uint64 number and should be unique within a client with the same connection ID. Web PubSub Service records the `ackId` and messages with the same `ackId` are treated as the same message. The service refuses to broker the same message more than once, which is useful in retry to avoid duplicated messages. For example, if a client sends a message with `ackId=5` and fails to receive an ack response with `ackId=5`, then the client retries and sends the same message again. In some cases, the message is already brokered and the ack response is lost for some reason. The service rejects the retry and response an ack response with `Duplicate` reason.
122136

123137
#### Ack Response
124138

@@ -139,7 +153,7 @@ Format:
139153

140154
* The `ackId` associates the request.
141155

142-
* `success` is a bool and indicate whether the request is successfully processed by the service. If it is `false`, clients need to check the `error`.
156+
* `success` is a bool and indicate whether the request is successfully processed by the service. If it's `false`, clients need to check the `error`.
143157

144158
* `error` only exists when `success` is `false` and clients should have different logic for different `name`. You should suppose there might be more type of `name` in future.
145159
- `Forbidden`: The client doesn't have the permission to the request. The client needs to be added relevant roles.
@@ -163,7 +177,7 @@ The permission of a client can be granted in several ways:
163177

164178
#### 1. Assign the role to the client when generating the access token
165179

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

168182
For example, let's sign a JWT token that has the permission to send messages to `group1` and `group2`:
169183

0 commit comments

Comments
 (0)