dunglas / mercure

🪽 An open, easy, fast, reliable and battery-efficient solution for real-time communications
https://mercure.rocks
GNU Affero General Public License v3.0
3.98k stars 297 forks source link

[Question] How publish/subscribe private message #926

Open kevcomparadise opened 4 months ago

kevcomparadise commented 4 months ago

Hi,

I am trying to get private messages working on Mercure, but I am unable to receive the messages. Could you provide me with the steps to follow?

I have configured the JWT for the subscriber like this: { "mercure": { "publish": [ "*" ] } }

And the JWT for the publisher like this: { "mercure": { "subscribe": [ "https://example.com/users/foo/{?topic}" ] } }

There are no errors when I publish with this configuration, but when I check the second parameter "topic" and set "private=On", my client stops receiving anything (without this, it receives just fine).

image

Did I miss something?

P.S.: I have tried with urlencode() and without, with the same result. (https://github.com/dunglas/mercure/issues/591#issuecomment-2139154587)

dunglas commented 4 months ago

Can you show us the headers of the SSE request? The JWT must be in a cookie or an Authorization header. Double check that it is sent properly.

Also, put the hub in debug mode and check the logs, you'll see more details.

kevcomparadise commented 4 months ago

Thanks for your response

Capture d’écran du 2024-07-22 22-53-34

Token : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJodHRwczovL2V4YW1wbGUuY29tL3VzZXJzL2Zvby97P3RvcGljfSJdfX0.et4JVCzC1cUMYv52od-oyQbFEx7547INTYFs1RtzSLM

Log of subscriber : mercure-1 | {"level":"info","ts":1721681751.3551211,"logger":"http.handlers.mercure","msg":"New subscriber","subscriber":{"id":"urn:uuid:1fa20f31-3bb0-4446-b22a-9a6a0a1ad36a","last_event_id":"","remote_addr":"172.29.0.1:53430","topic_selectors":["https://example.com/users/foo/{?topic}"],"topics":["https://example.com/books/1"]}}

Log publish : mercure-1 | {"level":"debug","ts":1721681911.0625815,"logger":"http.handlers.mercure","msg":"Update published","update":{"id":"urn:uuid:5233012e-2aa1-468e-86ee-4582087b5df7","type":"","retry":0,"topics":["https://example.com/users/foo/?topic=https://example.com/books/1"],"private":true,"data":"{\"hello\" : \"world\"}"},"remote_addr":"172.29.0.1:57898"}