feat(teams): persist + refresh IdP subject token at login (spec 074, MCP-1036)#601
Open
Dumbris wants to merge 1 commit into
Open
feat(teams): persist + refresh IdP subject token at login (spec 074, MCP-1036)#601Dumbris wants to merge 1 commit into
Dumbris wants to merge 1 commit into
Conversation
…MCP-1036) Today HandleCallback fetched userinfo then discarded the provider token. When teams.store_idp_tokens is enabled, capture the IdP access + refresh token at login and persist it encrypted (AES-256-GCM) via the credential store as an idp_subject_token record keyed by userID (empty serverKey). Adds GetValidIDPSubjectToken: returns a non-expired token, refreshing via the provider refresh_token grant when expired/near-expiry; when no valid token can be produced (absent, store disabled, expired-and-not-refreshable, or refresh failed) it returns ErrReauthRequired — never a stale token. This is the prerequisite seam consumed by the credential resolver (Path A token exchange, MCP-1039). Default-off: with store_idp_tokens false (default) or no encryption key, login behaves exactly as before — no storage. Persist is best-effort: a write failure never breaks login. - OAuthProvider.RefreshAccessToken: refresh_token grant (RFC 6749 §6) - OAuthHandler.credStore + SetCredentialStore; wired in teams/setup.go - TDD: capture-when-enabled, no-storage-when-disabled, refresh-near-expiry, expired-not-refreshable -> re-auth, absent -> re-auth, store-disabled -> re-auth FR-004, FR-005, FR-006. Related #588 (T2 config), #587 (T1 store). Co-Authored-By: Paperclip <noreply@paperclip.ing>
Deploying mcpproxy-docs with
|
| Latest commit: |
6344481
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1b70ce16.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://074-t3-idp-subject-token.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 26968052572 --repo smart-mcp-proxy/mcpproxy-go
|
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 T3 (MCP-1036). Builds on T1 (#587 credential store) and T2 (#588 config), both merged.
Today
HandleCallbackfetches userinfo then discards the provider token. This PR captures it whenteams.store_idp_tokensis enabled and adds a get-or-refresh seam that never serves a stale token.What changed
oauth_handler.go): after code exchange + user upsert, whenstore_idp_tokensis on, persist the IdP access + refresh token encrypted (AES-256-GCM) via the credential store as anidp_subject_tokenrecord keyed by userID (emptyserverKey). Best-effort — a write failure never breaks login.idp_subject_token.go):GetValidIDPSubjectToken(ctx, userID)returns a non-expired token, refreshing via the providerrefresh_tokengrant when expired/near-expiry (60s skew). When no valid token can be produced — absent, store disabled, expired-and-not-refreshable, or refresh failed — it returnsErrReauthRequired, never a stale token (FR-005). This is the prerequisite consumed by the credential resolver (Path A, MCP-1039).oauth_providers.go):OAuthProvider.RefreshAccessToken(refresh_token grant, RFC 6749 §6).teams/setup.go): construct the broker store fromMCPPROXY_CRED_KEY/teams.credential_encryption_keyand attach viaSetCredentialStore.Default-off (FR-006)
With
store_idp_tokensfalse (default) or no encryption key configured, login behaves exactly as before — no storage, store constructed disabled, capture silently skipped.Tests (TDD,
-tags server)ErrReauthRequiredErrReauthRequiredErrReauthRequiredVerification
go build -tags server ./cmd/mcpproxy✅ andgo build ./cmd/mcpproxy(personal unaffected) ✅go test -tags server ./internal/teams/... -race✅ (all packages)gofmt/go vetclean; CI lint config clean on changed filesDocs
No docs change, matching T1/T2 precedent (neither shipped docs for these keys). The feature is server-edition, default-off, and not yet user-consumable until the resolver + header injection land (T6+). Consolidated spec-074 user docs belong with that completion.
Related #588, #587. Blocks MCP-1039 (T6 resolver).
Gate 3: opening for review/CI only — I do not merge.