Skip to content

feat(teams): TokenExchanger — RFC 8693 + Entra OBO (spec 074, MCP-1037) - #600

Merged
Dumbris merged 1 commit into
mainfrom
feat/074-t4-token-exchanger
Jun 9, 2026
Merged

Dumbris merged 1 commit into
mainfrom
feat/074-t4-token-exchanger

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

Spec 074 T4 — the TokenExchanger that mints per-user upstream credentials for the server-edition token broker (internal/teams/broker/). Builds on T1 (CredentialStore, #587) and T2 (auth_broker config, #588), both merged.

golang.org/x/oauth2 has no native RFC 8693 support (golang/oauth2#409), so the exchange POST is hand-rolled.

What it does

  • mode=token_exchange (RFC 8693): grant_type=urn:ietf:params:oauth:grant-type:token-exchange, subject_token + subject_token_type, resource (RFC 8707) + scope.
  • mode=entra_obo (Microsoft Entra On-Behalf-Of): grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, assertion, requested_token_use=on_behalf_of, client_secret_post.
  • Subject token = the stored IdP token from T3 (CredentialStore.Get(userID, "")). Response parsed → access token + expiry + scopes, cached via store.Put(userID, serverKey, …).
  • Error sanitization: authorization-server failures surface only the HTTP status + standard OAuth error code — never error_description, the raw body, or request secrets. Nothing is cached on failure.

FR-007, FR-008, FR-009.

Tests (TDD)

Against an httptest mock token endpoint:

  • RFC 8693 happy path (param assertions + audience/scope propagation + caching)
  • Entra OBO mode
  • Sanitized error mapping (asserts no error_description/secret/subject-token leak, nothing cached)
  • Missing subject token (clean error, endpoint never hit)

Verification

  • go test -tags server -race ./internal/teams/broker/ ✅
  • go build -tags server ./cmd/mcpproxy + go build ./cmd/mcpproxy ✅
  • golangci-lint run --build-tags server ./internal/teams/broker/... → 0 issues ✅

No user-facing surface yet (the auth_broker config schema shipped in T2); wiring into the request path is T5. No docs diff required.

Related: spec 074 (MCP-1033). Blockers MCP-1034 / MCP-1035 merged.

… (spec 074, MCP-1037)

Hand-rolled OAuth token exchange for the server-edition upstream token
broker (golang.org/x/oauth2 has no native RFC 8693 — golang/oauth2#409).

- mode=token_exchange: grant_type token-exchange, subject_token +
  subject_token_type, resource (RFC 8707) + scope.
- mode=entra_obo: jwt-bearer grant + assertion + requested_token_use=
  on_behalf_of, client_secret_post auth.
- Subject token read from the CredentialStore IdP record (T3); result
  parsed to access token + expiry + scopes and cached via the store.
- Authorization-server errors sanitized: only HTTP status + OAuth error
  code surfaced, never error_description, body, or request secrets.
  Nothing cached on failure.

TDD: httptest mock token endpoint covers rfc8693 happy path, entra mode,
audience/scope propagation, sanitized error mapping, and missing subject
token. FR-007, FR-008, FR-009.

Co-Authored-By: Paperclip <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4248cd5
Status: ✅  Deploy successful!
Preview URL: https://68677d64.mcpproxy-docs.pages.dev
Branch Preview URL: https://feat-074-t4-token-exchanger.mcpproxy-docs.pages.dev

View logs

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: feat/074-t4-token-exchanger

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (24 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 26967977479 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@mcpproxy-gatekeeper mcpproxy-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gatekeeper approval — Codex review verdict: ACCEPT.

This approval is posted automatically by the MCPProxy Gatekeeper App on behalf of the Codex reviewer (verdict of record lives in the Paperclip review thread). Author≠approver satisfied; QA + CI gates enforced separately.

Auto-approved per Model B (MCP-1249).

@Dumbris Dumbris closed this Jun 9, 2026
@Dumbris Dumbris reopened this Jun 9, 2026
@Dumbris
Dumbris enabled auto-merge (squash) June 9, 2026 07:01
@Dumbris
Dumbris merged commit 0c8da42 into main Jun 9, 2026
58 checks passed
Dumbris added a commit that referenced this pull request Jun 15, 2026
…am (spec 074, MCP-1039) (#688)

* feat(broker): CredentialResolver — per-user-only ordering + policy seam (spec 074, MCP-1039)

Add the per-user credential resolver (T6) that selects which brokered
credential to inject on a proxied request. Strict per-user-only ordering
(FR-013/FR-014), with no shared or static fallback:

  1. valid cached per-user credential (refreshed if near-expiry);
  2. else token-exchange / Entra OBO from the stored IdP subject token;
  3. else, for oauth_connect upstreams the user has not connected, an
     actionable NotConnectedError carrying the connect URL;
  4. else ErrNoCredential.

- Single-flight coalescing per (user, server) so concurrent acquisitions
  do not trigger duplicate upstream token flows (golang.org/x/sync).
- PolicyHook seam (FR-015) evaluated per call before a credential is
  returned; ships with an allow-all default (no policy engine yet).
- Unauthenticated callers and a disabled store are rejected up front.
- Exchanger/Connector/ConnectorProvider interfaces decouple the resolver
  from the concrete TokenExchanger (T4) and OAuthConnector (T5); both
  satisfy the interfaces via compile-time assertions.

TDD: each ordering branch, near-expiry refresh (token-exchange + connect),
unconnected -> connect-URL error, unauthenticated reject, store-disabled,
policy-denied, no-static-fallback, and single-flight under -race.

Related: spec 074 (MCP-1033). Builds on T3 (#601), T4 (#600), T5 (#602), all merged to main.

Co-Authored-By: Paperclip <[email protected]>

* fix(broker): address review on CredentialResolver — singleflight ctx, double-exchange, reconnect error

Review (MCP-2490 / Critic) on PR #688:

- must-fix: detach the caller's context inside the single-flight closure with
  context.WithoutCancel. The flight runs the acquisition once for all co-pending
  callers; inheriting the first caller's cancellation let a single client
  disconnect/timeout broadcast ctx.Err() to every waiter for the same
  (user, server). Per-caller cancellation still applies at the policy/return
  layer (caller's original ctx).
- advisory: collapse the per-mode acquire/refresh paths so a near-expiry
  token-exchange miss no longer calls Exchange twice (refresh-then-fallthrough);
  a single Exchange now covers both cache-miss and near-expiry.
- advisory: an already-connected oauth_connect user whose refresh fails now gets
  an actionable reconnect error (NotConnectedError.Reason) instead of a
  misleading "never connected" message; the connect URL is still surfaced.
- advisory: document that the Exchanger (T4) and Connector (T5) persist their
  results themselves, so the resolver never calls store.Put.

Tests: add single-flight caller-cancellation detach, no-double-exchange on
near-expiry failure, and connect-flow refresh-fail -> reconnect. Full broker
suite green under -tags server -race; golangci-lint v2.5.0 clean.

Co-Authored-By: Paperclip <[email protected]>

* docs(auth-broker): document per-user credential resolution ordering (spec 074, MCP-1039)

Add a "Credential resolution" section describing the resolver's strict
per-user-only ordering (cached/refresh -> token-exchange/OBO -> actionable
connect-URL error -> no-credential), the no-shared/static-fallback guarantee,
single-flight coalescing, and the policy-decision seam. Keeps the feature doc
consistent with the CredentialResolver added in this PR (review follow-up).

Co-Authored-By: Paperclip <[email protected]>

---------

Co-authored-by: Paperclip <[email protected]>
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