symfony/mercure

401 Unauthorized returned always for subscriptions endpoint

pppupls opened this issue · 1 comments

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)

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();