Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 Unauthorized returned always for subscriptions endpoint #102

Open
pppupls opened this issue Jun 28, 2023 · 2 comments
Open

401 Unauthorized returned always for subscriptions endpoint #102

pppupls opened this issue Jun 28, 2023 · 2 comments

Comments

@pppupls
Copy link

pppupls commented Jun 28, 2023

hello
mb somedoby can help me?
i try to get all subscriptions via subscription API
but i always get HTTP/1.1 401 Unauthorized returned for "http://mercure/.well-known/mercure/subscriptions"

my code

$this->httpClient->request('GET', $_ENV['MERCURE_PUBLISH_URL'] . '/subscriptions', [
'headers' => [
'Authorization' => 'Bearer ' . $_ENV['MERCURE_JWT_TOKEN'],
'Content-Type' => 'application/ld+json',
]
])->getContent();

Originally posted by @pppupls in #26 (comment)

@smagolexandr
Copy link

smagolexandr commented Aug 8, 2023

hi, you should generate subscriber jwt token like this:

 $key = "SubscriberSecret";
 $payload = [
      'mercure' => [
           'publish' => ['*'],
           'subscribe' => ['*'],
           'payload' => []
      ],
 ];

$jwt = JWT::encode($payload, $key, 'HS256');

and then use it instead of your env var

$this->httpClient->request('GET', $_ENV['MERCURE_PUBLISH_URL'] . '/subscriptions', [
    'headers' => [
        'Authorization' => 'Bearer ' . $jwt,
        'Content-Type' => 'application/ld+json',
    ]
])->getContent();

@Arkemlar
Copy link

It would be nice if somebody explain how to achieve this without * in subscribe claim.
It seems I must provide correct topic name but I don't know it. Things like /.well-known/mercure/subscriptions/{topic}/{subscriber} or https://mercure.rocks/.well-known/mercure/subscriptions/{topic}/{subscriber} not works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants