fix(auth): populate OAuth scopes from server metadata discovery - #7267
Open
chelsealong wants to merge 1 commit into
Open
chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
CredentialsManager._populate_auth_scheme() only copied the discovered authorization/token URLs onto the auth scheme's OAuth flows, ignoring the scopes_supported field that RFC8414 discovery documents (and FastMCP's discovery endpoint) also return. Callers had to duplicate those scopes manually in the AuthScheme even though auto-discovery already had them. Fixes google#7266
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
CredentialsManager._populate_auth_scheme()auto-discovers OAuth2/OIDCserver metadata (RFC 8414 / RFC 9728, e.g. as served by FastMCP) and uses
it to fill in the
authorizationUrl/tokenUrlfields of anExtendedOAuth2auth scheme's flows when they are missing. The discoveryresponse also carries
scopes_supported, but that field was discarded —callers had to duplicate the server's supported scopes by hand in their
AuthSchemeconfiguration even though auto-discovery already had them.This adds the same "fill in only if currently empty" treatment to
scopesfor each OAuth flow (implicit,password,clientCredentials,authorizationCode), mirroring the existing URL-population logic.Fixes #7266
Test plan
Added an assertion to the existing
test_populate_auth_scheme_successtest verifying thatflows.authorizationCode.scopesis populated fromAuthorizationServerMetadata.scopes_supportedafter a successfuldiscovery.
Verified the test fails without the fix (by reverting only the source
change and re-running):
And passes with the fix applied:
Full
tests/unittests/authsuite (252 tests) also passes:pre-commit run(ruff, isort, pyink, addlicense, ADK compliance checks,codespell) passes on both changed files.
AI assistance disclosure
This change was authored with the assistance of an AI coding agent
(Claude Code), which implemented the fix, added the test, and verified
it against the existing test suite.
🤖 Generated with Claude Code