feat: support Cloudflare Global API Key authentication#34
feat: support Cloudflare Global API Key authentication#34tjuranek wants to merge 2 commits intocloudflare:mainfrom
Conversation
Add support for authenticating with Cloudflare's Global API Key (X-Auth-Email + X-Auth-Key headers) alongside the existing OAuth and Bearer token methods. This enables users who prefer the legacy Global API Key to use the MCP server without needing to create scoped API tokens. - Add `global_api_key` variant to AuthProps discriminated union - Detect X-Auth-Email + X-Auth-Key headers in incoming requests - Generalize getUserAndAccounts to accept either Bearer or Global API Key credentials - Update GlobalOutbound to inject the correct auth headers based on auth type (Bearer vs X-Auth-Email/X-Auth-Key) - Refactor executor and server to pass OutboundAuth instead of raw token strings - Add tests for isGlobalApiKey detection - Update executor tests to use OutboundAuth type Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Hey — I know this is an AI-assisted PR so I want to be upfront about that, but the motivation is I realize it's a tradeoff — the Global API Key is less secure since it grants full account access — Happy to make any changes needed to get this mergeable. Let me know if there's anything you'd want |
|
Why cant you use user or account api tokens? |
Summary
X-Auth-Email+X-Auth-Keyheaders, alongside the existing OAuth and Bearer token methodsGlobalOutboundprops — same isolation pattern as Bearer tokens (fix: move API token injection to GlobalOutbound via props #28), never entering the dynamic worker isolategetUserAndAccountsis generalized to accept either auth style (backward-compatible, still accepts a plain string)OutboundAuthdiscriminated union replaces the rawapiToken: stringplumbing through the executor and server, soGlobalOutboundinjects the correct headers (Authorization: BearervsX-Auth-Email/X-Auth-Key)Files changed
src/auth/types.tsglobal_api_keyvariant toAuthPropsunionsrc/auth/oauth-handler.tsbuildCloudflareAuthHeaders, generalizegetUserAndAccountssrc/auth/api-token-mode.tsisGlobalApiKeydetection +handleGlobalApiKeyRequesthandlersrc/index.tsGlobalOutboundprops to support both auth types, wire up Global API Key checksrc/executor.tsapiToken: stringwithOutboundAuthunionsrc/server.tsgetOutboundAuthhelper, passOutboundAuthto executorREADME.mdTest plan
isGlobalApiKeycorrectly detectsX-Auth-Email+X-Auth-Keyheaders (5 test cases)buildCloudflareAuthHeadersreturns correct headers for both auth types (2 test cases)isDirectApiToken,extractBearerToken,buildAuthPropstests still pass (unchanged)OutboundAuthtype instead of raw stringwrangler dev— Global API Key request successfully authenticates,tools/listreturns both tools,executetool runs code against the Cloudflare APInpm run checkclean (format, lint, typecheck, test)🤖 Generated with Claude Code