Repository navigation
fix(indiekit): return error instead of redirect for API GET requests with invalid bearer token - #912
Merged
paulrobertlloyd merged 1 commit intoAug 24, 2026
Conversation
Previously, any GET request that failed authentication was redirected to the login page, even when the client sent an Authorization header. This broke Micropub clients like Omnibear that query the endpoint with a bearer token but no session cookie. Now, GET requests that include an Authorization header or accept JSON receive a 401 error response instead of a login redirect. Fixes getindiekit#825
Collaborator
|
Nice! Thanks @aciccarello 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When a GET request to the Micropub query endpoint includes an
Authorization: Bearertoken but authentication fails, the middleware now returns an error response (401/403) instead of redirecting to the login page.Why
The
authenticate()middleware was redirecting all failing GET requests to/session/login, regardless of whether the request was from a browser or an API client. Micropub clients like Omnibear send a bearer token on GET requests but have no session cookie, and were receiving a 302 redirect instead of a usable error response.POST requests were already handled correctly (passed to the error handler). This fix brings GET requests in line with that behaviour when an
Authorization: Bearerheader is present.Changes
packages/indiekit/lib/indieauth.js: detect API-style GET requests (those with anAuthorization: Bearerheader orAccept: application/json) and pass errors tonext(error)instead of redirectingpackages/endpoint-micropub/test/integration/403-query-invalid-me.js: new integration test that verifies a bearer token GET request returns 403 instead of redirecting when the token'smedoes not match the publicationFixes #825