[Question] [Serverless] How can I send a message to an individual client using REST API?
See original GitHub issueDear Sirs,
I have studied the examples and I fully understand the architecture of Azure SignalR. I was able to broadcast messages from Postman. Also, I was able to run a chat example and was able to exchange messages.
The issue is: in a serverless scenario, how would I identify the id of an individual connected user? How Javascript clients can obtain their ID on Azure SignalR Service? This is needed because I want to send individual messages to a given user when his/her command gets processed on the backend. For example, in my use case, I would use a Azure Function to process a command that can take minutes to be executed.
What I have tried:
Using trace log on javascript client side, I was able to find an ID during negotiation:
Information: SSE connected to https://accendis-wefinance.service.signalr.net:5001/client/?hub=chat&id=61Ztvpa0KEQeKkJBgB2ZPQ&access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1MzEzNTY4OTcsImV4cCI6MTUzMTM1ODY5NywiaWF0IjoxNTMxMzU2ODk3LCJhdWQiOiJodHRwczovL2FjY2VuZGlzLXdlZmluYW5jZS5zZXJ2aWNlLnNpZ25hbHIubmV0OjUwMDEvY2xpZW50Lz9odWI9Y2hhdCJ9.NBFYcQaq-pl3c31AAeKmrLBIGnw-uON_MNWY0yMvJ_Y Utils.ts:165:20
So then I tried to build a new request using the id like this:
POST /api/v1-preview/hub/chat/user/61Ztvpa0KEQeKkJBgB2ZPQ HTTP/1.1
Host: accendis-wefinance.service.signalr.net:5002
Content-Type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE1MzEzMTgyMTUsImV4cCI6MTU2Mjg1OTQ5NCwiYXVkIjoiaHR0cHM6Ly9hY2NlbmRpcy13ZWZpbmFuY2Uuc2VydmljZS5zaWduYWxyLm5ldDo1MDAyL2FwaS92MS1wcmV2aWV3L2h1Yi9jaGF0L3VzZXIvNjFadHZwYTBLRVFlS2tKQmdCMlpQUSIsInN1YiI6IiJ9.aVhw0AyQ-WuT9NIymFzESn6Gv3R3zLedddqCngLzxFg
Cache-Control: no-cache
Postman-Token: 329b9cbd-8f86-4e62-8a3f-c5e23b8af025
{ "target": "newMessage0", "arguments": [ {
"sender": "mario",
"text": "API rest do SignalR"
} ] }
And as result, I receive a 202 but nothing happens on client side.
How can I see what really happened?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Thanks @chenkennt
It works!
For sake of completeness, here is an example of token generation (negotiation) Azure Function in Javascript.
Claims.NameIdentifier
maps tosub
in jwt:On the client, the negotiation and connection process can be done like this:
Thanks for your help again!
I don’t think @mariomeyrelles is putting any userId to the input binding for SignalR service, he was generating the access token by himself and adding the userId as part of the token signature.