workers-oauth-provider
AGENTS.md1.9k starsChanged 2 months agoMITView on GitHub
@cloudflare/workers-oauth-provider is a production-grade OAuth 2.1 provider library for Cloudflare Workers. It implements authorization code flow with PKCE, OAuth discovery, client registration, token exchange, audience validation, and encryption of sensitive data stored in KV. Primary use case: This library powers authorization for MCP (Model Context Protocol) servers. MCP servers are OAuth Resource Servers, and this library provides both protected-resource middleware and the authorization server functionality needed to secure them. This library was largely written with Claude AI assistance, with all…
- Installs packages
Trending
More talk lately.about the whole repository
Who's talking about cloudflare/workers-oauth-provider
- A Hacker News story“Cloudlflare builds OAuth with Claude and publishes all the prompts”Hacker News · Jun 2, 2025 · 889 points
- @baldurbjarnason.com“A question I got over on Mastodon was about a project done by Cloudflare engineers, who claimed that an LLM …”Bluesky · Jun 4, 2025 · 64 likes
- @phillipcarter.dev“Many such cases: github.com/cloudflare/w... > I was trying to validate my skepticism. I ended up proving …”Bluesky · Jun 2, 2025 · 6 likes
- @skorfmann.com“github.com/cloudflare/w...”Bluesky · May 30, 2025 · 5 likes
- @tech-trending.bsky.social“GitHub - cloudflare/workers-oauth-provider: OAuth provider library for Cloudflare Workers…”Bluesky · Jun 3, 2025 · 2 likes
The biggest 5 of 53 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 53
Talked about on GitHub, Bluesky and Hacker News (53 times).
On GitHub · 44
- Mar 5, 2025explore Backend for Frontend (BFF) architecture pattern — chr33s/shopflare2 reactions
- Aug 16, 2026chore: bump the dependencies group across 1 directory with 13 updates — alandotcom/trainheroic-unofficial1 reaction · 2 comments
- Jul 27, 2026chore(deps): bump the minor-and-patch group across 1 directory with 26 updates — blakeox/courtlistener-mcp1 reaction · 1 comment
- Jul 6, 2026chore(deps): bump the minor-and-patch group across 1 directory with 25 updates — blakeox/courtlistener-mcp1 reaction · 1 comment
- Jun 29, 2026chore(deps): bump the minor-and-patch group across 1 directory with 26 updates — blakeox/courtlistener-mcp1 reaction · 1 comment
39 more on GitHub
- Jun 22, 2026chore(deps): bump the minor-and-patch group across 1 directory with 25 updates — blakeox/courtlistener-mcp1 reaction · 1 comment
- Jun 15, 2026chore(deps): bump the minor-and-patch group across 1 directory with 26 updates — blakeox/courtlistener-mcp1 reaction · 1 comment
- Jun 13, 2026Bump @cloudflare/workers-oauth-provider from 0.7.2 to 0.8.0 — martinthommesen/snow-mcp1 reaction · 1 comment
- Dec 22, 2025chore(deps): bump the cloudflare group across 1 directory with 3 updates — llu77/-lmm1 reaction · 2 comments
- Oct 5, 2026build(deps): bump @cloudflare/workers-oauth-provider from 0.8.1 to 1.2.1 — ProvisioInsights/LivingAtlas0 reactions
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /cod-server — TaharBn12/ecom10 reactions · 2 comments
- Oct 5, 2026Bump the npm-major group across 1 directory with 3 updates — Nishfleet/05090 reactions · 2 comments
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /cod-server — bighadj22/codflow0 reactions · 1 comment
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /cod-server — juldas3/codflow0 reactions · 1 comment
- Oct 5, 2026build(deps): bump the production-minor-patch group with 6 updates — isomorphic-team/isomorphic-app0 reactions
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.0.5 to 1.2.1 — PortNumber53/mcp-jira-thing0 reactions
- Oct 5, 2026deps(deps): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.2.1 — Spelling-Creator/spelling-creator0 reactions · 1 comment
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /cod-server — krimo-g13/codflow0 reactions · 1 comment
- Oct 5, 2026chore(deps)(deps): bump the npm-minor-patch group with 12 updates — pmaxhogan/healthy0 reactions · 1 comment
- Oct 5, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /cod-server — TaharBn12/codflowv20 reactions · 1 comment
- Oct 5, 2026deps(deps): bump the cloudflare-runtime group across 1 directory with 4 updates — JohnTarbox/takemetothefair-cloudflare0 reactions · 2 comments
- Oct 4, 2026build(deps): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.2.1 — wakita181009/vault-mcp0 reactions
- Oct 4, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 in /apps/worker — MOVEI144/CF-edge-mcp-kit0 reactions · 1 comment
- Oct 4, 2026Bump the dev-tooling group across 1 directory with 8 updates — dc28vivek/splittab-mcp0 reactions
- Oct 4, 2026build(deps): bump the cloudflare group across 1 directory with 2 updates — nyuchi/mongodb-mcp0 reactions · 3 comments
- Oct 3, 2026deps: bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.2.1 — mazze93/github-mcp-gateway0 reactions
- Oct 1, 2026Bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.2.1 in /worker — Agent9AI/keendreams-security0 reactions
- Oct 1, 2026Bump the npm-dependencies group across 1 directory with 22 updates — umbraco/Umbraco-Engage-MCP-Dev0 reactions
- Oct 1, 2026Bump the runtime group with 2 updates — profplum700/jules-mcp0 reactions
- Sep 30, 2026build(deps): Bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.1.0 — Raoof128/gmail-mcp0 reactions
- Sep 30, 2026build(deps): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.1.0 — matcha-ai-test/banking-mcp0 reactions
- Sep 29, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.1.0 — hamo/schwab-mcp0 reactions
- Sep 29, 2026build(deps): bump the production-dependencies group across 1 directory with 5 updates — simhskal/goodreads-mcp0 reactions · 1 comment
- Sep 29, 2026chore(deps-dev): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.2.1 in the dev-majors group across 1 directory — chrischall/mcp-connector0 reactions
- Sep 28, 2026Bump the remote-dependencies group in /remote with 2 updates — ta3leem-tools/ta3leem-mcp0 reactions
- Sep 28, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.4 to 1.1.0 in /cod-server — ot2dz/codflow0 reactions · 1 comment
- Sep 28, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.2.1 — Global-Strategic-Technologies/gst-website0 reactions · 1 comment
- Sep 28, 2026deps: bump @cloudflare/workers-oauth-provider from 0.10.3 to 1.1.0 — sametbasbug/orbit-remote-mcp0 reactions
- Aug 18, 2026Bump @cloudflare/workers-oauth-provider from 0.10.2 to 0.10.3 — anotb/driftglass0 reactions
- Aug 17, 2026build(deps): bump the cloudflare group across 1 directory with 2 updates — caseyWebb/yet-another-meal-planner0 reactions
- Aug 17, 2026chore(deps): bump @cloudflare/workers-oauth-provider from 0.8.1 to 0.10.3 in /worker — JGtHb/MCPbox0 reactions · 1 comment
- Aug 15, 2026build(deps): bump @cloudflare/workers-oauth-provider from 0.8.2 to 0.10.3 — erpipe-org/erpipe0 reactions · 1 comment
- Aug 15, 2026Bump @cloudflare/workers-oauth-provider from 0.8.3 to 0.10.3 in /apps/drafts-mcp — mxpf/write-placid0 reactions
- Aug 2, 2026Bump @cloudflare/workers-oauth-provider from 0.0.11 to 0.8.3 — ShinoharaTa/healthtool0 reactions
On Bluesky · 8
- Jun 4, 2025A question I got over on Mastodon was about a project done by Cloudflare engineers, who claimed that an LLM agent let them build it faster… — @baldurbjarnason.com64 likes and reposts · 2 replies
- Jun 2, 2025Many such cases: github.com/cloudflare/w... > I was trying to validate my skepticism. I ended up proving myself wrong. — @phillipcarter.dev6 likes and reposts · 1 reply
- May 30, 2025github.com/cloudflare/w... — @skorfmann.com5 likes and reposts
- Jun 3, 2025GitHub - cloudflare/workers-oauth-provider: OAuth provider library for Cloudflare Workers… — @tech-trending.bsky.social2 likes and reposts
- Jun 3, 2025🌐CloudlflareはClaudeでOAuthを構築し、すべてのプロンプトを公開します https://github.com/cloudflare/workers-oauth-provider/ via #HackerNews — @kdmsnr.com1 likes and repost
3 more on Bluesky
- Jun 3, 2025#Cloudlflare builds #OAuth with #Claude and publishes all the #prompts github.com/cloudflare/w... — @apardo.spluca.org1 likes and repost
- Jun 2, 2025"NOOOOOOOO!!!! You can't just use an LLM to write an auth library!" "haha gpus go brrr" github.com/cloudflare/w... — @bennyjamins.bsky.social1 likes and repost
- Jun 3, 2025Cloudlflare builds OAuth with Claude and publishes all the prompts View Article | Join the HN Conversation Summary of HN discussion 🧵👇… — @hncompanion.com0 likes and reposts · 1 reply
On Hacker News · 1
- Jun 2, 2025Cloudlflare builds OAuth with Claude and publishes all the prompts889 points · 529 comments
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
When modifying OAuth functionality, always check the latest published MCP specification (not drafts):
- Distinctive: line 30
When in doubt about OAuth behavior, the MCP specification takes precedence for MCP-related use cases.
- Distinctive: line 104
All public methods and interfaces must have JSDoc documentation
- Distinctive: line 140
Only token holders can decrypt their associated props
- Distinctive: line 223
All checks must pass before merge.
- Very specific: line 263
Run npm run check before considering work done
- Distinctive: line 264
Add tests for new functionality
- Distinctive: line 265
Document public APIs with JSDoc
- Distinctive: line 266
Consider security implications of changes
- Very specific: line 282
Use any type without explicit justification
- Distinctive: line 288
Update this file when:
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Project overview
@cloudflare/workers-oauth-provider is a production-grade OAuth 2.1 provider library for Cloudflare Workers. It implements authorization code flow with PKCE, OAuth discovery, client registration, token exchange, audience validation, and encryption of sensitive data stored in KV.
Primary use case: This library powers authorization for MCP (Model Context Protocol) servers. MCP servers are OAuth Resource Servers, and this library provides both protected-resource middleware and the authorization server functionality needed to secure them.
This library was largely written with Claude AI assistance, with all code thoroughly reviewed by Cloudflare security engineers.
MCP specification compliance
When modifying OAuth functionality, always check the latest published MCP specification (not drafts):
- Specification: https://modelcontextprotocol.io/specification/2026-07-28
- Authorization section: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization
- Authorization server discovery: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/authorization-server-discovery
- Client registration: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/client-registration
- Security considerations: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/security-considerations
This library must be feature-complete with the latest published MCP spec version. Key MCP auth requirements:
- MCP servers are OAuth Resource Servers with protected resource metadata (RFC 9728)
- MCP clients use Resource Indicators (RFC 8707), and servers validate token audience
- Client registration supports pre-registration and Client ID Metadata Documents (CIMD)
- Dynamic Client Registration (DCR) is deprecated in MCP 2026-07-28 and retained for compatibility
- Authorization responses use issuer identification (RFC 9207)
- Streamable HTTP transport uses OAuth 2.1 for authentication
When in doubt about OAuth behavior, the MCP specification takes precedence for MCP-related use cases.
Repository structure
workers-oauth-provider/
├── src/
│ ├── oauth-provider.ts # Core provider implementation
│ ├── oauth-capabilities.ts # Pure server/client metadata capability policy
│ ├── oauth-client-metadata.ts # Typed DCR parsing and CIMD resolution pipeline
│ ├── oauth-http.ts # CORS and scope helpers shared by both hosts
│ ├── oauth-error.ts # OAuthError: what callbacks and validators throw
│ ├── oauth-consent.ts # Consent and upstream sign-in transactions (MCP confused-deputy MUSTs)
│ └── ema/ # Enterprise-Managed Authorization pipeline
├── tests/
│ ├── oauth-provider.test.ts # Comprehensive provider integration suite
│ ├── oauth-capabilities.test.ts # Pure capability policy tests
│ ├── public-api.test.ts # Pins the package's runtime exports
│ ├── setup.ts # Vitest setup and mocking
│ └── mocks/
│ └── cloudflare-workers.ts
├── examples/ # Runnable Workers, typechecked and e2e-tested in workerd
│ └── split-workers/ # The README quick start in full, e2e-tested
├── conformance/ # Black-box MCP authorization conformance matrix
│ ├── README.md # Scope, revision coverage, and traceability
│ ├── shared.ts # Typed Worker RPC contract and fixture constants
│ ├── spec-versions.ts # Ordered MCP authorization revision timeline
│ ├── support/ # Workerd lifecycle and OAuth client
│ ├── upstream/ # Official @modelcontextprotocol/conformance runner, run in CI
│ └── worker/ # Real Wrangler Worker with local KV
├── dist/ # Build output (tsdown)
├── docs/
│ ├── advanced-configuration.md
│ └── resource-servers.md # Hosting resources in the same Worker or over a Service Binding
├── .github/workflows/
│ ├── ci.yml # PR validation
│ ├── release.yml # Changesets-based npm publishing
│ └── pkg-pr-new.yml # PR preview packages
├── storage-schema.md # KV namespace data structure docs
├── HISTORY.md # Kenton's original project history
├── SECURITY.md # Vulnerability reporting
└── README.md # Usage documentationAudit-oriented architecture: Request orchestration and storage-backed OAuth behavior remain in src/oauth-provider.ts. Typed OAuth client metadata parsing plus CIMD fetching and resolution live in src/oauth-client-metadata.ts; pure authorization-server/client capability policy lives in src/oauth-capabilities.ts. Consent pages and third-party sign-in transactions (the MCP confused-deputy protections: __Host- browser binding, single-use state, signed remembered approvals) live in src/oauth-consent.ts. The experimental Enterprise-Managed Authorization validation pipeline is isolated in src/ema/ so its JWT and trust-boundary code can be reviewed independently.
Setup
npm install # Install dependencies
npm run build # Build with tsdownNode 24+ required.
Commands
| Command | What it does |
npm run build | Builds single-file ESM bundle with tsdown |
npm run check | Runs typecheck + tests |
npm run typecheck | TypeScript type checking (no emit) |
npm run test | Runs vitest test suite |
npm run test:conformance | Runs MCP auth conformance tests |
npm run test:conformance:upstream | Runs the official MCP conformance runner against the conformance Worker |
npm run test:watch | Runs vitest in watch mode |
npm run prettier | Formats all files with Prettier |
Code standards
TypeScript
- Strict mode enabled
- Target: ES2021, Module: ES2022
- All public methods and interfaces must have JSDoc documentation
- Private fields use
#prefix (modern TS private fields)
Naming conventions
PascalCasefor classes, interfaces, enumscamelCasefor methods, variablesSCREAMING_SNAKE_CASEfor constantsImplsuffix for internal implementationsOptionssuffix for configuration interfaces
Architecture patterns
PImpl pattern: The public OAuthProvider class wraps a private OAuthProviderImpl. This prevents TypeScript private methods from being accidentally exposed over RPC in Cloudflare Workers.
export class OAuthProvider {
#impl: OAuthProviderImpl;
fetch(...) { return this.#impl.fetch(...); }
}Dual handler support: The library supports both ExportedHandler (plain objects) and WorkerEntrypoint (classes) patterns. Maintain both for backwards compatibility.
Formatting
Prettier with 120 character line width. Run npm run prettier before committing.
Security considerations
This is a security-critical OAuth library. All changes must consider:
Token storage:
- Secrets (tokens, authorization codes) are stored as SHA-256 hashes only
- Props are encrypted with AES-GCM, key wrapped with the token itself
- Only token holders can decrypt their associated props
Validation:
- Redirect URIs validated against XSS payloads
- Client IDs validated (including CIMD URL validation)
- PKCE enforced for public clients (S256 method)
- Scope downscoping validated per RFC 6749 Section 3.3
Refresh token rotation:
- Dual refresh tokens: current + previous both valid
- Handles network failure cases gracefully
- Previous token invalidated only after new token first used
Testing
Tests use vitest with custom mocks for Cloudflare Workers APIs.
npm run test # Full suite, including conformance
npm run test:conformance # MCP authorization conformance only
npm run test:watch # Watch modeMain integration test: tests/oauth-provider.test.ts
MCP authorization conformance: conformance/ contains black-box tests for every dated authorization revision represented by the official MCP conformance timeline. Wrangler's createTestHarness() runs a real Worker in Workerd with a local KV binding; tests exercise public OAuthProvider and OAuthHelpers interfaces and include requirement traceability in conformance/README.md.
Examples: examples/ Workers import @cloudflare/workers-oauth-provider, which tsconfig.json paths and each wrangler.jsonc alias map to src/, so they are built from source and need no package.json of their own. The README shows short excerpts and links here for the full code; keep the two consistent.
Mock implementations:
MockKV— In-memory KV with TTL simulationMockExecutionContext— ctx.props supportcreateMockRequest()— HTTP request builder
Coverage areas:
- OAuth metadata discovery endpoints
- Authorization code flow with PKCE
- Token exchange and refresh flows
- Client registration (RFC 7591)
- Grant management and revocation
- Error responses and validation
- Scope downscoping
- Resource-aware audience validation
Test pattern:
beforeEach(() => {
mockEnv = createMockEnv();
mockCtx = new MockExecutionContext();
oauthProvider = new OAuthProvider(options);
});
afterEach(() => {
mockEnv.OAUTH_KV.clear();
});Contributing
Changesets
Changes affecting the public API or bug fixes need a changeset:
npx changeset # Interactive: select semver bump, write descriptionThe changesets bot keeps a Version Packages PR (changeset-release/*) open on main and v0. Merging it publishes to npm, moves dist-tags and creates the git tag and GitHub release, none of which can be undone. Only a human maintainer merges it. An agent may read it, check that its version and changelog are right, and report what it would publish, but must never merge, approve, or auto-merge it, even with admin rights or when asked to "finish the release". Hand it back to a human instead.
Pull request process
CI runs on every PR:
npm ci— Clean installnpm run build— Build with tsdownnpm run check— Typecheck + tests- Prettier format check
All checks must pass before merge.
0.x maintenance branch (v0)
main carries the 1.0 line. Fixes that 0.x users need are cherry-picked to v0 in a PR against that branch, with their changeset. v0 carries its own ci.yml and a push-triggered release.yml (a workflow_run release would give changesets/action the default branch's github.sha), and publishes through .github/changeset-publish.sh, which uses the v0 dist-tag once npm's latest is 1.x so a hotfix never displaces latest. Both release workflows share the npm-publish concurrency group.
Bonk (AI code review)
Mention /bonk or @ask-bonk in PR comments to get AI-powered code review and suggestions. Bonk can analyze code, suggest fixes, and even auto-commit improvements.
Semver: changes that invalidate tokens or refresh tokens must be minor
Any change that alters the format of data stored on grants (e.g. the resource field) can silently invalidate existing refresh tokens. These changes must be released as a minor version bump, not a patch. This applies to any change where tokens issued by the previous version would fail validation against the new version.
RFC compliance
This library implements multiple OAuth/security RFCs. When making changes, maintain compliance with:
- OAuth 2.1 (draft-ietf-oauth-v2-1-13)
- OAuth 2.0 Bearer Token Usage (RFC 6750)
- OAuth 2.0 Token Revocation (RFC 7009)
- OAuth 2.0 Dynamic Client Registration (RFC 7591, deprecated by MCP 2026-07-28)
- PKCE (RFC 7636)
- OAuth 2.0 Authorization Server Metadata (RFC 8414)
- OAuth 2.0 Token Exchange (RFC 8693)
- Resource Indicators for OAuth 2.0 (RFC 8707)
- OAuth 2.0 Authorization Server Issuer Identification (RFC 9207)
- OAuth 2.0 Protected Resource Metadata (RFC 9728)
- Client ID Metadata Documents (draft spec)
- OpenID Connect RP Metadata Choices 1.0
Generated files
dist/— Generated bynpm run build, don't hand-editpackage-lock.json— Generated bynpm install, don't hand-edit
Boundaries
Always:
- Run
npm run checkbefore considering work done - Add tests for new functionality
- Document public APIs with JSDoc
- Consider security implications of changes
- Maintain backwards compatibility for handler patterns
Ask first:
- Adding new dependencies (this ships to users with zero runtime deps)
- Changing KV storage schema (requires migration planning)
- Modifying OAuth endpoints or flows
- Adding new feature flags
Never:
- Hardcode secrets or API keys
- Bypass constructor validation
- Store unhashed tokens or secrets in KV
- Break existing handler patterns
- Use
anytype without explicit justification - Force push to main
- Merge, approve, or enable auto-merge on a Version Packages PR: releases are for humans only
Keeping AGENTS.md updated
Update this file when:
- Adding new modules or significant features
- Changing project structure
- Modifying build/test tooling
- Adding new code patterns or conventions
- Changing contribution workflows
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

