Skip to content

chore: add --oauth per-connection OAuth sign-in to the local dev server - #421

Closed
Rodriguespn wants to merge 3 commits into
feat/local-http-oauthfrom
feat/local-oauth-resource-server
Closed

Rodriguespn wants to merge 3 commits into
feat/local-http-oauthfrom
feat/local-oauth-resource-server

Conversation

@Rodriguespn

@Rodriguespn Rodriguespn commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Adds --oauth to the local --http dev server as an alternative to a PAT. The server advertises itself as an OAuth-protected resource (RFC 9728, same model as the hosted endpoint); each connecting MCP client signs in with Supabase OAuth in its own browser popup and attaches its own bearer token per request. No local token validation — tokens are forwarded to the Management API unchanged, identical trust model to PAT mode today.

api.supabase.com currently rejects the loopback resource value the OAuth client SDK must send. The mgmt-api OAuth authorize/token endpoints need to accept loopback (127.0.0.1/localhost) /mcp resource URLs, not just the hosted mcp.supabase.com one, before sign-in against production will succeed.

A follow up in the mgmt-api is still needed

Verification

Verified end-to-end (discovery, 401 challenge, DCR, browser consent, token exchange, authenticated call) against a local mock authorization server only — documented in CONTRIBUTING.md and at CLI startup.

@coveralls

coveralls commented Sep 8, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 34290519484

Coverage increased (+0.05%) to 96.463%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 49 of 49 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3621
Covered Lines: 3511
Line Coverage: 96.96%
Relevant Branches: 535
Covered Branches: 498
Branch Coverage: 93.08%
Branches in Coverage %: Yes
Coverage Strength: 60.04 hits per line

💛 - Coveralls

@Rodriguespn
Rodriguespn marked this pull request as ready for review September 8, 2026 23:04
@Rodriguespn
Rodriguespn requested a review from a team as a code owner September 8, 2026 23:04
@Rodriguespn Rodriguespn changed the title feat: add --oauth per-connection OAuth sign-in to the local dev server chore: add --oauth per-connection OAuth sign-in to the local dev server Sep 8, 2026
@Rodriguespn
Rodriguespn force-pushed the feat/local-oauth-resource-server branch from a33c9d3 to ab55388 Compare September 8, 2026 23:24
Adds --oauth support to the local --http dev server as an OAuth
resource server (RFC 9728): it advertises
/.well-known/oauth-protected-resource/mcp pointing at the Supabase
authorization server (mirroring the hosted endpoint's scopes), and
each connecting MCP client signs in for itself in its own browser
popup and sends its own bearer token on every request -- matching
the per-user consent model the hosted MCP server already has.

- local-http-entry.ts: serves the discovery route when
  oauthAuthorizationServer is set; challenges a missing bearer with a
  spec-correct 401 + WWW-Authenticate (RFC 6750) whose
  resource_metadata points back at the discovery route. The
  advertised resource URL is derived from the request's
  already-validated Host header, so a client dialing localhost or
  127.0.0.1 both satisfy the OAuth client SDK's same-origin check.
  No local token validation: the server forwards whatever bearer it
  receives to the Management API unchanged, which remains the sole
  authority -- identical trust model to the existing PAT mode.
- cli.ts: --oauth points the resource server at --api-url (or
  api.supabase.com) and warns at startup about the known platform
  limitation below.

Not yet usable against production (documented in CONTRIBUTING.md and
at CLI startup): api.supabase.com currently rejects the loopback
`resource` value the OAuth client SDK is required to send (RFC
8707), pending a platform-side widening of its OAuth resource
validation for loopback /mcp URLs. Verified end-to-end (discovery,
401 challenge, DCR, browser consent, token exchange, authenticated
tool call) against a local mock authorization server; not yet
provable against the real Supabase authorization server.

Filed as chore: not yet usable end-to-end against production, so it
must not trigger a release-please version bump until the platform
side ships and this is confirmed working for real.

Co-Authored-By: Claude <[email protected]>
@Rodriguespn
Rodriguespn force-pushed the feat/local-oauth-resource-server branch from ab55388 to 037c25f Compare September 10, 2026 23:21
@Rodriguespn
Rodriguespn changed the base branch from main to feat/local-http-oauth September 10, 2026 23:21
@Rodriguespn
Rodriguespn added this pull request to stack #405 September 10, 2026 23:21
OAUTH_SCOPES_SUPPORTED in local-http-entry.ts is a static mirror of the
hosted server's advertised scopes (needed so --oauth still works offline
and against a mock authorization server in tests). Add an e2e test that
fetches the real https://mcp.supabase.com/.well-known/oauth-protected-resource/mcp
discovery endpoint and fails with an exact add/remove diff plus the file
to edit if the mirror has gone stale, instead of letting the gap surface
later as a confusing "insufficient scope" error.

Bounds the check with a 15s timeout and guards the JSON parse so a
network hiccup or a non-JSON response (e.g. a CDN interstitial) produces
the same actionable message instead of a raw fetch/SyntaxError.

Co-Authored-By: Claude <[email protected]>
@Rodriguespn
Rodriguespn force-pushed the feat/local-oauth-resource-server branch from c1bce53 to 4b691a9 Compare September 11, 2026 10:56
@Rodriguespn

Copy link
Copy Markdown
Contributor Author

Closing this one in favor of #404

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