azure-webpubsub icon indicating copy to clipboard operation
azure-webpubsub copied to clipboard

Azure Pubsub REST API Example

Open mackensiealvarezz opened this issue 4 years ago • 2 comments

Describe the bug

I'm trying to use the Rest API to send a message, but the documentation is a bit unclear on where to pass the primary key? Is the key provided inside of the Azure portal suppose to be placed in the header or body?

To Reproduce

POST XXX.webpubsub.azure.com/api/hubs/test/:send BODY: { "message": "test" }

Further technical details

I'm using the REST api because our system is built using PHP and there isn't an SDK currently.

mackensiealvarezz avatar Sep 08 '21 00:09 mackensiealvarezz

  • [ ] Add the Auth part to the documentation

A sample broadcast request:

POST https://demo.webpubsub.azure.com/api/hubs/chat/:send?api-version=2021-05-01-preview HTTP/1.1
Host: demo.webpubsub.azure.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2MzEwODA3MTAsImV4cCI6MTYzMTA4MTAxMCwiaWF0IjoxNjMxMDgwNzEwLCJhdWQiOiJodHRwczovL2RlbW8ud2VicHVic3ViLmF6dXJlLmNvbS9hcGkvaHVicy9jaGF0LzpzZW5kP2FwaS12ZXJzaW9uPTIwMjEtMDUtMDEtcHJldmlldyJ9.xxx
Content-Type: text/plain
Content-Length: 5

hello

The required header is the Authorization header that uses the JWT bearer token to auth the request. For example for the above sample request, the token contains the below header and payload. The aud should be exactly the same as the request URL.

image

Also here is a sample code generating the JWT token in JavaScript

vicancy avatar Sep 09 '21 05:09 vicancy

That worked right away! Thank you for the help!

mackensiealvarezz avatar Sep 09 '21 14:09 mackensiealvarezz