feat(oauth): add headless activation flow and fix redirect allowlist - #50
Open
ddpie wants to merge 1 commit into
Open
feat(oauth): add headless activation flow and fix redirect allowlist#50ddpie wants to merge 1 commit into
ddpie wants to merge 1 commit into
Conversation
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.
English
Why
The standard OAuth flow requires the browser and the MCP client on the same machine: the client listens on a loopback port and the authorization code is redirected there. When the agent runs on a remote host and the browser is on a laptop, that redirect lands on the wrong machine and authorization cannot complete without SSH port forwarding.
Separately, the redirect allowlist rejected VS Code entirely. VS Code submits four redirect URIs in one dynamic client registration — two loopback forms plus
https://vscode.dev/redirectandhttps://insiders.vscode.dev/redirect— and rejecting any single entry fails the whole registration. Those two hosted brokers hand the flow back to the originating editor instance, which is what makes VS Code work over Remote-SSH, Dev Containers and Codespaces without port forwarding.Changes
/activate, a self-service authorization route with no client redirect_uri and no PKCE. Feishu returns to this service over HTTPS and/callbackrenders the resulting 30-day MCP token for the user to copy into their client's request headers. No port forwarding, no SSH tunnel, no client-side capability required./registerand/authorize.localhost, all of127.0.0.0/8, and[::1]— instead of onlylocalhostand127.0.0.1.Cache-Control: no-storeandReferrer-Policy: no-referrer.The activation route grants no new authority:
/tokenalready issues 30-day tokens over the standard flow, and revocation is unchanged because mcp-middleware re-reads the user's Feishu token from Secrets Manager on every request, so revoking a user invalidates every token they hold.The widening of the allowlist is strictly limited to the loopback block and those two broker hosts. Non-allowlisted https hosts, broker-lookalike subdomains, brokers over plain http, and non-loopback http hosts all stay rejected.
Verification
./scripts/test.sh— 34 test files, 716 tests passed (24 new)中文
背景
标准 OAuth 流程要求浏览器与 MCP 客户端在同一台机器上:客户端监听 loopback 端口,授权码被重定向到那里。当 Agent 运行在远程主机、浏览器在笔记本上时,该重定向会落到错误的机器,必须靠 SSH 端口转发才能完成授权。
另一个独立问题是 redirect allowlist 完全拒绝了 VS Code。VS Code 在一次动态客户端注册中提交四个 redirect URI —— 两个 loopback 形式,加上
https://vscode.dev/redirect与https://insiders.vscode.dev/redirect—— 其中任意一项被拒都会导致整次注册失败。这两个托管跳板负责把流程交还给发起它的编辑器实例,正是 VS Code 在 Remote-SSH、Dev Containers 和 Codespaces 下无需端口转发的原因。改动
/activate自助授权入口,不带客户端 redirect_uri,也不使用 PKCE。飞书通过 HTTPS 回到本服务,/callback渲染出有效期 30 天的 MCP token 供用户复制到客户端请求头。无需端口转发、SSH 隧道或任何客户端特殊能力。/register与/authorize均接受 VS Code 的两个托管跳板域。localhost、整个127.0.0.0/8以及[::1]—— 取代原先只认localhost和127.0.0.1。Cache-Control: no-store与Referrer-Policy: no-referrer。激活入口不授予任何新权限:
/token在标准流程下本来就签发 30 天 token;吊销语义也未变,因为 mcp-middleware 每次请求都会重新从 Secrets Manager 读取该用户的飞书 token,撤销用户即使其持有的所有 token 立即失效。allowlist 的放宽严格限定在 loopback 段与上述两个跳板域。非白名单 https 域、形似跳板的子域、走明文 http 的跳板域,以及非 loopback 的 http 域,均保持拒绝。
验证
./scripts/test.sh—— 34 个测试文件、716 条测试通过(新增 24 条)