fix(auth): recover expired dynamic client registrations - #3260
Draft
daleselaji-dev wants to merge 4 commits into
Draft
fix(auth): recover expired dynamic client registrations#3260daleselaji-dev wants to merge 4 commits into
daleselaji-dev wants to merge 4 commits into
Conversation
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.
Problem
An OAuth client can remain permanently stuck after a dynamically registered client secret expires. The stored registration is reused, and token endpoint
invalid_clientresponses are treated as ordinary failures, so re-authorization retries with the same dead credentials.Root Cause
OAuthClientProviderloadedclient_secret_expires_atbut never used it. The token storage protocol also had no way to clear the persisted client registration or tokens when the authorization server rejected the client credentials.Solution
Treat a non-zero, past
client_secret_expires_atas an unusable stored registration and clear it before the next flow. Also detectinvalid_clientfrom the response body regardless of whether the authorization server uses HTTP 400 or 401, clear the bound credentials, and allow the next flow to register again.Changes
TokenStoragesetters to receiveNoneto clear stored tokens or client information.invalid_clientduring token exchange or refresh.Testing
py -m pytest tests/client/test_auth.py tests/client/test_scope_bug_1630.py tests/client/auth/extensions/test_client_credentials.py tests/client/auth/extensions/test_identity_assertion.py -q— 172 passed, 1 xfailed.py -m ruff format --check src/mcp/client/auth/oauth2.py tests/client/test_auth.py tests/client/test_scope_bug_1630.py tests/client/auth/extensions/test_client_credentials.py tests/client/auth/extensions/test_identity_assertion.py— passed.py -m ruff check src/mcp/client/auth/oauth2.py tests/client/test_auth.py tests/client/test_scope_bug_1630.py tests/client/auth/extensions/test_client_credentials.py tests/client/auth/extensions/test_identity_assertion.py— passed.git diff --check— passed.Compatibility/Risk
This changes the
TokenStoragesetter contract so storage implementations must treatNoneas deletion. The runtime behavior is limited to expired or server-rejected registrations; valid registrations and non-invalid_clientfailures retain their existing flow.Notes for Reviewer
Pyright is unverified locally because the incremental worktree has no repository
.venv. An alternate environment had mismatchedmcp_types,httpx2, and project dependency versions and reported broad pre-existing import/type diagnostics; those results are not presented as a passing typecheck.Linked Issue
Closes #3256