Repository navigation
feat: add opt-in token passthrough for running behind an OAuth gateway - #295
Open
CVThien2k2 wants to merge 1 commit into
Open
CVThien2k2 wants to merge 1 commit into
CVThien2k2 wants to merge 1 commit into
Conversation
With BACKLOG_TOKEN_PASSTHROUGH=true (or --backlog-token-passthrough) the HTTP transport takes the Backlog access token from each request's `Authorization: Bearer` header and the space from `X-Backlog-Host`, falling back to BACKLOG_DOMAIN. This lets a gateway that already holds users' Backlog OAuth grants serve users from several spaces through one server. - X-Backlog-Host is limited to <space>.backlog.com / .backlog.jp / .backlogtool.com or exactly BACKLOG_DOMAIN, so the token never reaches another host; anything else is answered 400 invalid_host. - A Backlog rejection of the token becomes a 401 so the gateway can refresh and retry. Responses are JSON in this mode, and the 2025-era SSE fallback is buffered, so the status can still change after the tool runs. The mode is off by default. stdio, API key, multi-organization and the built-in OAuth server are unchanged; combining passthrough with BACKLOG_OAUTH_CLIENT_ID or the stdio transport is rejected at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Adds an opt-in token passthrough mode for the HTTP transport, for deployments where a gateway in front of the server already holds each user's Backlog OAuth grant (for example an internal MCP hub serving users from several Backlog spaces).
When
BACKLOG_TOKEN_PASSTHROUGH=true(or--backlog-token-passthrough) is set:Authorization: Bearerheader.X-Backlog-Host, falling back toBACKLOG_DOMAINwhen the header is absent.X-Backlog-Hostis limited to<space>.backlog.com,<space>.backlog.jp,<space>.backlogtool.com, or exactlyBACKLOG_DOMAIN, so the token is never sent to another host. Anything else is answered400 invalid_host.reportBacklogAuthError) becomes a401withWWW-Authenticate, so the gateway can refresh and retry. Responses are JSON in this mode, and the 2025-era SSE fallback is buffered (stateless streams end with the result), so the status can still change after the tool runs.Compatibility
Purely additive; the mode is off by default.
BACKLOG_OAUTH_CLIENT_ID, or with the stdio transport, is rejected at startup.backlogAuthContextand adds acreateTokenPassthroughBacklogClientRegistrynext to the OAuth one.Changes
src/auth/backlogHost.ts: host validation and the per-request space context.src/auth/tokenPassthroughMiddleware.ts: Bearer +X-Backlog-Hostmiddleware.src/utils/backlogClientRegistry.ts:createTokenPassthroughBacklogClientRegistry.src/httpMcpServer.ts,src/index.ts: thetokenPassthroughoption and CLI flag / env var..env.example: a "Token Passthrough" section.Testing
pnpm run lint,pnpm run format,pnpm test(821 passed) andpnpm run build.tools/listreturns all tools; stdio without an API key still fails as before.🤖 Generated with Claude Code