Skip to content

fix(indiekit): return error instead of redirect for API GET requests with invalid bearer token - #912

Merged
paulrobertlloyd merged 1 commit into
getindiekit:mainfrom
aciccarello:fix/micropub-query-bearer-token
Aug 24, 2026
Merged

paulrobertlloyd merged 1 commit into
getindiekit:mainfrom
aciccarello:fix/micropub-query-bearer-token

Conversation

@aciccarello

Copy link
Copy Markdown
Collaborator

What

When a GET request to the Micropub query endpoint includes an Authorization: Bearer token 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: Bearer header is present.

Changes

  • packages/indiekit/lib/indieauth.js: detect API-style GET requests (those with an Authorization: Bearer header or Accept: application/json) and pass errors to next(error) instead of redirecting
  • packages/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's me does not match the publication

Fixes #825

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
@paulrobertlloyd
paulrobertlloyd merged commit 69910bf into getindiekit:main Aug 24, 2026
1 check failed
@paulrobertlloyd

Copy link
Copy Markdown
Collaborator

Nice! Thanks @aciccarello 😄

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

Successfully merging this pull request may close these issues.

Micropub query endpoint does not accept Bearer token

2 participants