4

I am working on a project, in which I am building a publish-subscribe system through Azure Web PubSub Service. The JavaScript clients (subscribers) are connected through socket and able to receive the published message on the Hub and in the Group. For this I followed this tutorial: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/tutorial-pub-sub-messages?tabs=javascript

Everything is working fine, as I am in the POC phase yet. So currently I am publishing messages through JavaScript from above tutorial. But now I am starting to integrate it in my existing app which is developed in PHP. So I am thinking to use following Azure REST API for Web PubSub operation: https://learn.microsoft.com/en-us/rest/api/webpubsub/dataplane/web-pub-sub

Before this I worked on the Azure Graph APIs, in which I did an App Registration at Azure Portal with some Redirect URLs, and assign some permissions to access the resources. I did this for Outlook Mail, Overdrive, SharePoint and its very straight forward process to get the access token (JWT) to access the resources.

But I am stuck and unable to get the access token for Azure Web PubSub API. I need token to just Publish a message from PHP end by REST API. I checked in App Registration's > API permissions section, there is no permission for the Azure Web PubSub Service. I checked the same app in Enterprise application also. Did some hit and try, but didn't get the access token. I know the issue is with the permission.

Please help me to get the token for this, so will call the Web PubSub API, Or if I am missing something please help me to trace. Any suggestion are welcome. Thanks.

HarisH Sharma
  • 1,101
  • 1
  • 11
  • 38
  • Have you seen this post: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-authorize-from-application. You need to assign role through role assignment. – Thomas Jun 10 '22 at 01:55
  • Are you writing your code in C# or JavaScript? – Paul Smith Jun 11 '22 at 14:14
  • I completed my code for the client end in JavaScript and everything is working, I need to call web pubSub api from PHP. – HarisH Sharma Jun 12 '22 at 15:07

2 Answers2

0

I think you can make use of the following REST API endpoints:

Web Pub Sub - Grant Permission

https://learn.microsoft.com/en-us/rest/api/webpubsub/dataplane/web-pub-sub/grant-permission#webpubsubpermission enter image description here


Web Pub Sub - Generate Client Token

https://learn.microsoft.com/en-us/rest/api/webpubsub/dataplane/web-pub-sub/generate-client-token enter image description here

Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
0

Have you tried this?

  1. create app registration
  2. add roles
  3. invoke rest api passing client id and secret

https://learn.microsoft.com/en-us/answers/questions/878719/how-to-generate-token-for-azure-web-pub-sub-servic?comment=answer-880720&page=1#comment-1197765

Manuel
  • 1