fix(client): invalidate credentials and re-register when the authorization server changes (SEP-2352)#2271
Draft
mattzcarey wants to merge 1 commit into
Draft
fix(client): invalidate credentials and re-register when the authorization server changes (SEP-2352)#2271mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
…ation server changes (SEP-2352)
🦋 Changeset detectedLatest commit: e848b15 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Implements SEP-2352 (authorization server binding & migration) for the OAuth client. Draft because the invalidation trigger is behavioral and needs maintainer sign-off — see "Behavioral risk" below.
Spec
Draft spec,
basic/authorization/client-registration.mdx, "Authorization Server Binding":What changed
authInternal(discovery block,packages/client/src/client/auth.ts): after discovery resolves the authorization server, the previously recorded AS identity (cacheddiscoveryState.authorizationServerUrl/ cached metadataissuer/provider.authorizationServerUrl?.()) is compared against the freshly resolved identity. On a mismatch, the SDK callsprovider.invalidateCredentials?.('client')and('tokens'); the existing flow then sees no client information and re-registers with the new AS.client_idis an HTTPS URL (CIMD), no invalidation occurs — those client IDs are explicitly portable across ASes.invalidateCredentials('client')but does not implementsaveClientInformationwill get a thrown error ("OAuth client information must be saveable for dynamic registration") rather than silent reuse, matching the spec's SHOULD-surface-an-error guidance.OAuthClientProvider.clientInformation/saveClientInformation: implementations SHOULD persist client credentials keyed by the ASissuer.Canonical comparison key (flagging for maintainers)
The spec says credentials are keyed by the AS
issueridentifier. The comparison uses the validated AS metadataissuerwhere available, falling back to the AS URL when metadata is absent — under RFC 8414 the two coincide. To avoid false-positive invalidation when they textually diverge (trailing slash, issuer-vs-discovery-URL drift), a match on either the issuer or the AS URL is treated as "same AS". Happy to tighten this to issuer-only if preferred.Behavioral risk (flagging for a direction call)
Silently dropping credentials on AS change could surprise providers whose
discoveryStateis flaky — e.g. a provider that intermittently returns a stale or empty discovery state whileauthorizationServerUrl()still reports the old AS would trigger invalidation and a re-registration round-trip. Flagging the trigger condition for a direction call before this leaves draft.Land order
auth.ts/auth.test.ts. This branch is independent (offmain, not stacked); expect trivial test-file rebases depending on merge order.issvalidation) PR will touchauthInternal's code-exchange path and will rebase over this one.Validation
pnpm build:all,pnpm typecheck:all,pnpm lint:all— cleanpnpm --filter @modelcontextprotocol/client test— 370/370 pass (3 new tests in a standalonedescribeappended at the end ofauth.test.ts: AS change → invalidate + re-register; same AS → no invalidation; CIMD client_id + AS change → no invalidation, credentials reused)@modelcontextprotocol/clientDownstream impact
cloudflare/agents'
DurableObjectOAuthClientProvideralready implementsinvalidateCredentials('client')so this works; its storage keys client info per server-name+client_id rather than per-issuer — fully honoring SEP-2352's keying guidance would be an optional agents-side follow-up, not a break.Closes #2201