Hi Devender Singh,
In your code you’re generating the token with the hub name "Hub". When using Azure Web PubSub for Socket.IO, the service expects the token to be generated for the default Socket.IO hub (usually named socketio). That’s why the audience in your token is rejected.
- Update your token generation code to use the "socketio" hub instead of "Hub". For example: _webPubSubServiceClient = new WebPubSubServiceClient(hubConnectionString, "socketio"); var url = _webPubSubServiceClient.GetClientAccessUri(userId: userId); return Ok(new { url });.
- Ensure your client is connecting to the correct endpoint that aligns with the "socketio" hub.
The JWT token includes an "audience" claim that tells the Web PubSub service which endpoint it’s intended for. When using Socket.IO with Azure Web PubSub, the expected audience is built around the "socketio" hub. A mismatch here results in the 401 unauthorized error you're seeing.
https://learn.microsoft.com/en-us/azure/azure-web-pubsub/socketio-quickstart
https://learn.microsoft.com/en-us/azure/azure-web-pubsub/socket-io-howto-integrate-apim
If you have any further assistant, do let me know.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.