Skip to content

Allow OAuth U2M logins to send RFC 8707 resource indicators - #6621

Open
sunishsheth2009 wants to merge 2 commits into
databricks:mainfrom
sunishsheth2009:mcp-oauth-resource-indicator
Open

sunishsheth2009 wants to merge 2 commits into
databricks:mainfrom
sunishsheth2009:mcp-oauth-resource-indicator

Conversation

@sunishsheth2009

Copy link
Copy Markdown

Changes

Add a repeatable --resource flag to databricks auth login that sends RFC 8707 resource indicator(s) as resource query parameters on the OAuth authorization request. Threaded through u2m.PersistentAuth via a new WithResources option, appended to the authorization endpoint URL (preserving any query the endpoint already carries; the oauth2 library appends client_id/PKCE/etc. after). Requires --host (added to the discovery-incompatible flag list), since a resource indicator targets a specific workspace's /oidc.

Example:

databricks auth login \
  --host https://<workspace> \
  --client-id <app> \
  --resource https://<workspace>/ai-gateway/mcp-services/system.ai.github

produces:

https://<workspace>/oidc/v1/authorize?resource=https%3A%2F%2F<workspace>%2Fai-gateway%2Fmcp-services%2Fsystem.ai.github&client_id=<app>&code_challenge=...&redirect_uri=http%3A%2F%2Flocalhost%3A8020&response_type=code&scope=offline_access+all-apis&state=...

Why

Builds on #6594 (--client-id). A resource-aware authorization server can use the resource indicator to scope the login to a specific protected resource and drive that resource's own login before issuing the authorization code — e.g. a per-user connection credential behind an AI Gateway MCP service (system.ai.github), where the user must complete a downstream SaaS login the first time. Without the indicator the authorization server only sees client_id + user, not which connection the flow is for.

This is a draft / POC to enable end-to-end validation of that flow; the resource indicator is currently sent on the authorization request only (not the token exchange).

Tests

  • TestPersistentAuthResources — none / single / multiple resource params appear on the built authorize URL.
  • TestValidateDiscoveryFlagCompatibility--resource requires --host.
  • go test ./libs/auth/u2m/ ./cmd/auth/ pass; go vet clean; gofmt clean.

This pull request and its description were written by Isaac.

sunishsheth2009 and others added 2 commits September 10, 2026 22:25
Add a repeatable `--resource` flag to `databricks auth login` that sends
RFC 8707 resource indicator(s) as `resource` query parameters on the
authorization request. This lets the U2M browser flow scope the login to
a specific protected resource so the authorization server can drive that
resource's own login (e.g. a per-user connection behind an AI Gateway MCP
service) before issuing the authorization code.

The indicator is threaded through PersistentAuth via WithResources and
appended to the authorization endpoint URL, preserving any query the
endpoint already carries; the oauth2 library appends its own parameters
after. The flag requires `--host` (added to the discovery-incompatible
flag list) since it targets a specific workspace's /oidc.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

Copy link
Copy Markdown
Contributor

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 6621
  • Commit SHA: 43a67e9a28199f9b1bd7667812e3ef7c208a8adb

Checks will be approved automatically on success.

sunishsheth2009 added a commit to sunishsheth2009/ucode that referenced this pull request Sep 10, 2026
Give every coding agent a working login flow for connection-backed AI Gateway
mcp-services endpoints, done in the stdio proxy every agent already spawns — no
new library (cf. mcp-remote) and no per-agent OAuth app.

When AI Gateway has no per-user connection credential it answers with HTTP 401
(RFC 9728). The proxy's httpx auth hook already sees every response, so on a 401
for a connection-backed URL it runs the Databricks CLI U2M login with an RFC 8707
resource indicator (`databricks auth login --resource <mcp-url>`, using the CLI's
own registered redirect — no --client-id), then retries with a fresh token. A
resource-aware /oidc drives the connection's SaaS login before minting the token,
so the retry succeeds — transparently to the agent, which just sees the request
authenticate rather than a failed tools/list. A later credential revoke re-triggers
the login on the next 401.

New module mcp_connection_login holds connection_from_url + run_connection_login;
mcp_proxy._build_token_auth gains the login-on-401 retry. Unit-tested. Depends on
the CLI --resource flag (databricks/cli#6621) and /oidc resource handling (login).

Co-authored-by: Isaac <no-reply@databricks.com>
@sunishsheth2009
sunishsheth2009 marked this pull request as ready for review September 11, 2026 04:05
@github-actions

Copy link
Copy Markdown
Contributor

Approval status: pending

/cmd/auth/ - needs approval

Files: cmd/auth/login.go, cmd/auth/login_test.go
Suggested: @simonfaltum
Also eligible: @renaudhartert-db, @tanmay-db, @tejaskochar-db, @Divyansh-db, @hectorcast-db, @parthban-db, @mihaimitrea-db, @chrisst, @rauchy

/libs/auth/ - needs approval

Files: libs/auth/u2m/persistent_auth.go, libs/auth/u2m/persistent_auth_test.go
Suggested: @simonfaltum
Also eligible: @renaudhartert-db, @tanmay-db, @tejaskochar-db, @Divyansh-db, @hectorcast-db, @parthban-db, @mihaimitrea-db, @chrisst, @rauchy

General files (require maintainer)

Files: .nextchanges/cli/u2m-resource-indicator.md
Based on git history:

  • @simonfaltum -- recent work in cmd/auth/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db, @janniklasrose, @lennartkats-db, @rugpanov, @rclarey) can approve all areas.
See OWNERS for ownership rules.

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.

1 participant