Skip to content

feat: add withOAuthProtectedResource - #113

Merged
mandarini merged 3 commits into
mainfrom
raulb/migrate-oauth-protected-resource
Aug 14, 2026
Merged

feat: add withOAuthProtectedResource#113
mandarini merged 3 commits into
mainfrom
raulb/migrate-oauth-protected-resource

Conversation

@raulb

@raulb raulb commented Aug 12, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Fixes AI-1071

What is the current behavior?

withOAuthProtectedResource (RFC 9728 OAuth Protected Resource middleware, metadata route + 401 enrichment) lives in https://github.com/supabase-community/edge-function-mcp-sandbox.

What is the new behavior?

Adds withOAuthProtectedResource, resourceMetadataResponse, and unauthorizedResponse as a new top-level module (src/oauth-protected-resource/), exported from the package root. Docs/examples are generalized.

Additional context

This other PR updates its code to make use of this new function, updating the notes-app example over to this package.

@raulb raulb self-assigned this Aug 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@supabase/server@113

commit: 4aa7dfb

@raulb raulb changed the title feat: add oauth-protected-resource feat: add withOAuthProtectedResource Aug 12, 2026
@raulb
raulb marked this pull request as ready for review August 12, 2026 16:39
@raulb
raulb requested review from a team as code owners August 12, 2026 16:40
@mandarini
mandarini force-pushed the raulb/migrate-oauth-protected-resource branch from cb979a0 to 71af0c0 Compare August 13, 2026 09:25
@mandarini

Copy link
Copy Markdown
Collaborator

@raulb While rebasing this onto main I pushed some small commits: forwarding the platform second argument that withSupabase now consumes (post #88), wiring the ./oauth-protected-resource subpath export into tsdown/npm/JSR like the other submodules, and two behavior nits: the 401 enrichment no longer overwrites a WWW-Authenticate the handler already set, and the metadata endpoint now answers CORS (header on the 200, preflight on OPTIONS) so browser clients like MCP Inspector can read it. Routing, the 404 contract, and url.ts are untouched. Shout if you want any of it reverted.

@mandarini

Copy link
Copy Markdown
Collaborator

oh one more thing @raulb. Not a blocker. VSCode and Claude Code don't read the WWW-Authenticate hint. They probe /.well-known/oauth-protected-resource directly, and nothing serves that today. So those clients can't discover auth for functions using this middleware at all. That needs a platform-level fix (only the proxy can own the domain root). Is that on anyone's radar?

@raulb

raulb commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@raulb While rebasing this onto main I pushed some small commits: forwarding the platform second argument that withSupabase now consumes (post #88), wiring the ./oauth-protected-resource subpath export into tsdown/npm/JSR like the other submodules, and two behavior nits: the 401 enrichment no longer overwrites a WWW-Authenticate the handler already set, and the metadata endpoint now answers CORS (header on the 200, preflight on OPTIONS) so browser clients like MCP Inspector can read it. Routing, the 404 contract, and url.ts are untouched. Shout if you want any of it reverted.

@mandarini thank you! will review

oh one more thing @raulb. Not a blocker. VSCode and Claude Code don't read the WWW-Authenticate hint. They probe /.well-known/oauth-protected-resource directly, and nothing serves that today. So those clients can't discover auth for functions using this middleware at all. That needs a platform-level fix (only the proxy can own the domain root). Is that on anyone's radar?

@mandarini it was not on my radar. Scanned Linear and spotted this other issue. Is this what you're referring to? https://linear.app/supabase/issue/FDBKIN-15575/allow-hosting-well-known-endpoints-at-the-project-root-for-edge

@raulb

raulb commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@mandarini validated this with https://github.com/supabase-community/edge-function-mcp-sandbox/pull/9 and everything's working. I'll keep working on some other items separately, but let me know if this PR needs any more additional work. Thank you!

@mandarini

Copy link
Copy Markdown
Collaborator

@raulb Yes, that's exactly it. Clients that skip the WWW-Authenticate hint (VSCode, Claude Code) can only discover auth through a root-level /.well-known endpoint, so that ticket is the platform-side half of what this middleware does. One detail for whenever it gets built: the proxy will rewrite root probes to some internal path, and that target has to match what this middleware serves (today /{fn}/oauth-protected-resource), or the middleware can serve both. Nothing more needed on this PR from my side. Approving.

@mandarini
mandarini merged commit 3908590 into main Aug 14, 2026
9 checks passed
@mandarini
mandarini deleted the raulb/migrate-oauth-protected-resource branch August 14, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants