Web Pub Sub - Generate Client Token
Generate token for the client to connect Azure Web PubSub service.
POST {endpoint}/api/hubs/{hub}/:generateToken?api-version=2024-01-01
POST {endpoint}/api/hubs/{hub}/:generateToken?userId={userId}&role={role}&minutesToExpire={minutesToExpire}&api-version=2024-01-01&group={group}&clientType={clientType}
URI Parameters
| Name | In | Required | Type | Description |
|---|---|---|---|---|
|
endpoint
|
path | True |
string (url) |
HTTP or HTTPS endpoint for the Web PubSub service instance. |
|
hub
|
path | True |
string pattern: ^[A-Za-z][A-Za-z0-9_`,.[\]]{0,127}$ |
Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. |
|
api-version
|
query | True |
string |
The version of the REST APIs. |
|
client
|
query |
The type of client. Case-insensitive. If not set, it's "Default". For Web PubSub for Socket.IO, only the default value is supported. For Web PubSub, the valid values are 'Default' and 'MQTT'. |
||
|
group
|
query |
string[] |
Groups that the connection will join when it connects. |
|
|
minutes
|
query |
integer (int32) minimum: 1 |
The expire time of the generated token. |
|
|
role
|
query |
string[] |
Roles that the connection with the generated token will have. |
|
|
user
|
query |
string |
User Id. |
Responses
| Name | Type | Description |
|---|---|---|
| 200 OK |
Success Media Types: "text/plain", "application/json", "text/json" |
|
| Other Status Codes |
Error response Media Types: "text/plain", "application/json", "text/json" Headers x-ms-error-code: string |
Examples
WebPubSub_GenerateClientToken
Sample request
POST {endpoint}/api/hubs/hub1/:generateToken?userId=user1&minutesToExpire=5&api-version=2024-01-01&clientType=MQTT
Sample response
{
"token": "ABCDEFG.ABC.ABC"
}
Definitions
| Name | Description |
|---|---|
|
Client |
The response object containing the token for the client |
|
Error |
The error object. |
|
Inner |
|
|
Web |
The type of client. Case-insensitive. If not set, it's "Default". For Web PubSub for Socket.IO, only the default value is supported. For Web PubSub, the valid values are 'Default' and 'MQTT'. |
ClientTokenResponse
The response object containing the token for the client
| Name | Type | Description |
|---|---|---|
| token |
string |
The token value for the WebSocket client to connect to the service |
ErrorDetail
The error object.
| Name | Type | Description |
|---|---|---|
| code |
string |
One of a server-defined set of error codes. |
| details |
An array of details about specific errors that led to this reported error. |
|
| inner | ||
| message |
string |
A human-readable representation of the error. |
| target |
string |
The target of the error. |
InnerError
| Name | Type | Description |
|---|---|---|
| code |
string |
A more specific error code than was provided by the containing error. |
| inner |
WebPubSubClientType
The type of client. Case-insensitive. If not set, it's "Default". For Web PubSub for Socket.IO, only the default value is supported. For Web PubSub, the valid values are 'Default' and 'MQTT'.
| Value | Description |
|---|---|
| Default | |
| MQTT |