Skip to content

Embed auth fix #3: validate token in /auth/{authenticated,user} directly - #2290

Merged
lukemarsden merged 1 commit into
mainfrom
feature/001890-does-gatewaze-start-up
Apr 26, 2026
Merged

lukemarsden merged 1 commit into
mainfrom
feature/001890-does-gatewaze-start-up

Conversation

@lukemarsden

Copy link
Copy Markdown
Collaborator

Summary

PR #2289's /auth/authenticated fix didn't actually work because I missed that the endpoint is on insecureRouter — a separate subRouter that doesn't have extractMiddleware. So getRequestUser(r) always returned nil at the top of the handler.

E2E test confirmed: with the deployed code, curl -H "Authorization: Bearer hl-..." https://meta.helix.ml/api/v1/auth/authenticated still returns {"authenticated":false} even though the same Bearer token works fine on /api/v1/spec-tasks/....

Fix

In both /auth/authenticated and /auth/user handlers, resolve the token ourselves via s.authMiddleware.getUserFromToken(). That covers Authorization: Bearer, ?access_token=, and x-api-key callers.

Existing cookie / BFF session paths kept exactly as they were — this is purely an additional branch at the top of each handler.

Why two endpoints

The React app's account context loads the user in two steps:

  1. /auth/authenticated{authenticated: true} to skip the login redirect
  2. /auth/user → user object to populate state

Both need to recognize the embed token, otherwise the app either redirects to /login (step 1 fails) or never finishes initialization (step 2 fails).

Test plan

  • go build ./api/pkg/server/ clean
  • After deploy: curl -H "Authorization: Bearer ${HELIX_API_KEY}" https://meta.helix.ml/api/v1/auth/authenticated returns {"authenticated":true}
  • Embed iframe meta.helix.ml/embed/task/{id}?access_token={key} renders the task content (not the login redirect)

🤖 Generated with Claude Code

PR #2289's previous fix tried to read getRequestUser(r) at the top of
the handler, but /auth/authenticated and /auth/user live on the
insecureRouter — a separate subRouter that doesn't have
extractMiddleware. So getRequestUser always returned nil.

Resolve the token ourselves via s.authMiddleware.getUserFromToken().
That makes ?access_token=... and Authorization: Bearer work for these
two endpoints, which is what the React app needs to load the user
when embedded with no session cookie.

Cookie / session paths unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Spec-Ref: helix-specs@4628938:001890_do-gateways-start-up
@lukemarsden
lukemarsden merged commit ec41d76 into main Apr 26, 2026
1 check passed
@lukemarsden
lukemarsden deleted the feature/001890-does-gatewaze-start-up branch April 26, 2026 06:56
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.

1 participant