You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/concept-client-protocols.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,25 @@ The Web PubSub service provides two types of endpoints for clients to connect to
23
23
24
24
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}`.
25
25
26
-
Here is a general authorization workflow:
26
+
Here's a general authorization workflow:
27
27
28
28
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.
29
29
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.
31
45
32
46
<aname="simple_client"></a>
33
47
@@ -47,7 +61,7 @@ var client2 = new WebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', '
47
61
48
62
## The PubSub WebSocket client
49
63
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:
51
65
52
66
*`json.webpubsub.azure.v1`
53
67
*`protobuf.webpubsub.azure.v1`
@@ -112,13 +126,13 @@ The **PubSub WebSocket Client** supports `ackId` property for `joinGroup`, `leav
112
126
113
127
#### Behavior when No `ackId` specified
114
128
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.
116
130
117
131
#### Behavior when `ackId` specified
118
132
119
133
##### Idempotent publish
120
134
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.
122
136
123
137
#### Ack Response
124
138
@@ -139,7 +153,7 @@ Format:
139
153
140
154
* The `ackId` associates the request.
141
155
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`.
143
157
144
158
*`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.
145
159
-`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:
163
177
164
178
#### 1. Assign the role to the client when generating the access token
165
179
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.
167
181
168
182
For example, let's sign a JWT token that has the permission to send messages to `group1` and `group2`:
0 commit comments