Repository navigation
feat(teams): TokenExchanger — RFC 8693 + Entra OBO (spec 074, MCP-1037) - #600
Merged
Merged
Conversation
… (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]>
Deploying mcpproxy-docs with
|
| 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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 26967977479 --repo smart-mcp-proxy/mcpproxy-go
|
There was a problem hiding this comment.
✅ 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
enabled auto-merge (squash)
June 9, 2026 07:01
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Spec 074 T4 — the
TokenExchangerthat mints per-user upstream credentials for the server-edition token broker (internal/teams/broker/). Builds on T1 (CredentialStore, #587) and T2 (auth_brokerconfig, #588), both merged.golang.org/x/oauth2has 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.CredentialStore.Get(userID, "")). Response parsed → access token + expiry + scopes, cached viastore.Put(userID, serverKey, …).errorcode — nevererror_description, the raw body, or request secrets. Nothing is cached on failure.FR-007, FR-008, FR-009.
Tests (TDD)
Against an
httptestmock token endpoint:error_description/secret/subject-token leak, nothing cached)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_brokerconfig 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.