Repository navigation
Subscribing always results in a 401 after updating to Mercure 1.0 #1431
|
I have been working on updating my system to Mercure 1.0, by following the upgrade guide, and the information from the release notes The main changes I had to make were on updating the JWT structure, specifically by applying these changes from the breaking changes notes:
With this I managed to make publishing work, but I keep getting a 401 error when trying to subscribe via javascript's This is how my JWT looks like once decoded, for a token which is intended to allow subscribing to any topic: // Headers
{
"typ": "at+jwt",
"alg": "HS256"
}
// Payload
{
"iss": "MyIssuer",
"iat": 1791552014,
"exp": 1791638414,
"mercure": {
"subscribe": [
{
"match": "*"
}
]
},
"aud": "http://localhost:3080/.well-known/mercure",
"authorization_details": [
{
"type": "https://mercure.rocks/authorization-detail",
"actions": [
"subscribe"
],
"topics": [
{
"match": "*"
}
]
}
]
}On top of this, I have set One thing I don't know is what are the allowed values for the EDIT: Subscribers try to subscribe via: const hubUrl = new URL('http://localhost:3080/.well-known/mercure');
hubUrl.searchParams.append('match', 'https://example.com/some-topic');
hubUrl.searchParams.append('authorization', '...']); // The JWT is set here
const es = new EventSource(hubUrl); |
Replies: 2 comments 8 replies
|
Your token looks fine. 1.0 removed the For const es = new EventSource(hubUrl, { withCredentials: true });Outside the browser, or with |
|
@CaptainAni187's answer is right. Sorry for the confusion: until yesterday mercure.rocks was serving an outdated draft of the 1.0 docs, including the upgrade guide you followed. The updated guide now documents the change. The leftover A few details for your local setup:
|
Your token looks fine.
actionstakespublishand/orsubscribe, so["subscribe"]with{ "match": "*" }is right (the leftovermercureclaim is just ignored). The problem is how the token reaches the hub.1.0 removed the
authorizationquery parameter. From the "Migrate token presentation" section of the upgrade guide: "Theauthorizationquery parameter is gone and has no replacement", because RFC 9700 forbids access tokens in URLs. So the hub never sees your token and answers 401.For
EventSourcein the browser, which can't set headers, the replacement is the cookie. Its default name changed frommercureAuthorizationto__Secure-mercure_access_token. Since you're onhttp://localhost, keep i…