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=2023-07-01
POST {endpoint}/api/hubs/{hub}/:generateToken?userId={userId}&role={role}&minutesToExpire={minutesToExpire}&api-version=2023-07-01&group={group}

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

Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

Regex pattern: ^[A-Za-z][A-Za-z0-9_`,.[\]]{0,127}$

api-version
query True

string

The version of the REST APIs.

group
query

string[]

Groups that the connection will join when it connects.

minutesToExpire
query

integer

int32

The expire time of the generated token.

role
query

string[]

Roles that the connection with the generated token will have.

userId
query

string

User Id.

Responses

Name Type Description
200 OK

ClientTokenResponse

Success

Media Types: "text/plain", "application/json", "text/json"

Other Status Codes

ErrorDetail

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=2023-07-01

Sample Response

{
  "token": "ABCDEFG.ABC.ABC"
}

Definitions

Name Description
ClientTokenResponse

The response object containing the token for the client

ErrorDetail

The error object.

InnerError

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

ErrorDetail[]

An array of details about specific errors that led to this reported error.

inner

InnerError

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

InnerError