refactor(auth): resolve Cloudflare credentials through OAuth provider - #185
Draft
mattzcarey wants to merge 6 commits into
Draft
refactor(auth): resolve Cloudflare credentials through OAuth provider#185mattzcarey wants to merge 6 commits into
mattzcarey wants to merge 6 commits into
Conversation
mattzcarey
force-pushed
the
feat/external-api-token-resolution
branch
from
July 30, 2026 23:37
9fdfeb9 to
6f23438
Compare
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
Move direct Cloudflare bearer credentials behind
workers-oauth-provider'sresolveExternalTokenhook.The provider now owns bearer parsing, internal MCP access-token lookup, request dispatch, no-store error responses, and RFC 6750/9728 challenges. Our resolver runs only when the provider does not find one of its own tokens.
Direct credential behavior
The resolver uses the credential prefix as an ownership hint, following cloudflare/mcp-server-cloudflare#393:
cfat_: query one minimum-size/accounts?per_page=5page and require exactly one accountcfut_: query/userand/accountsin parallel and require a usercfoat_: same user-owned path, including Wrangler OAuth credentialsThe resolver produces a discriminated identity (
accountoruser) before building request props, so impossible combinations such as a null user with an arbitrary account list cannot cross the boundary. The existing token-hash identity cache remains. Its namespace moves to v4 for the new shape, and cached values are validated with the same Zod schema before use.Expected validation failures are converted to the provider's
ExternalTokenError:401 invalid_token403 insufficient_scopewith owner-specific scope guidance429andRetry-After502 server_errorThe Cloudflare OAuth authorization and refresh implementation is unchanged. Provider-issued MCP access tokens resolve internally and do not call the external resolver.
Provider release dependency
This currently pins the official pkg.pr.new build from cloudflare/workers-oauth-provider#272 because npm
0.8.3does not exportExternalTokenError.cloudflare/workers-oauth-provider#261 will publish these merged changes as
0.9.0. Before this PR is marked ready, replace the preview URL with exact0.9.0and refresh the lockfile.The provider upgrade also requires public OAuth clients to use PKCE and returns a bare challenge when credentials are missing. The OAuth route tests were updated for those released behaviors, without changing our upstream OAuth flow.
Compliance note
Direct Cloudflare API token support remains an explicit compatibility mode. It does not make an upstream Cloudflare credential an MCP-issued access token. OAuth remains the recommended MCP authorization path. This change makes compatibility-mode validation and error handling consistent with the provider and OAuth resource-server semantics.
Validation
npm cinpm run check(19 files, 295 tests)npx wrangler deploy --dry-run --env stagingnpm audit --omit=devreports the existing Hono advisory, unrelated to this change