How to generate token for Azure Web Pub Sub service REST call?

Dave Larson 21 Reputation points
2022-06-06T18:05:26.587+00:00

I would like to use the Azure Web PubSub Service REST call to send a message to a websocket.

[https://learn.microsoft.com/en-us/rest/api/webpubsub/dataplane/web-pub-sub/send-to-group][1]

POST https://contoso.com/api/hubs/thehub/groups/bd2c9778-7ec6-4ca4-8e8a-89be61ce51f3/:send?api-version=2021-10-01  
Authorization: Bearer 
Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
59 questions
0 comments No comments
{count} votes

Accepted answer
  1. Liangying Wei 756 Reputation points Microsoft Employee
    2022-06-08T01:37:35.993+00:00

    The Bearer token is a JWT token with your service AccessKey as the signing key and the full REST API path as the audience.
    A sample code in JS:

    const bearerToken = jwt.sign({}, connectionString.accessKey, {
            audience: request.url,
            expiresIn: "1h",
            algorithm: "HS256",
          });
    

0 additional answers

Sort by: Most helpful