Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/google/adk/auth/credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,38 @@ async def _populate_auth_scheme(self) -> bool:
return False

flows = auth_scheme.flows
scopes = (
{scope: "" for scope in metadata.scopes_supported}
if metadata.scopes_supported
else {}
)

if flows.implicit and not flows.implicit.authorizationUrl:
flows.implicit.authorizationUrl = metadata.authorization_endpoint
if flows.implicit and scopes and not flows.implicit.scopes:
flows.implicit.scopes = scopes
if flows.password and not flows.password.tokenUrl:
flows.password.tokenUrl = metadata.token_endpoint
if flows.password and scopes and not flows.password.scopes:
flows.password.scopes = scopes
if flows.clientCredentials and not flows.clientCredentials.tokenUrl:
flows.clientCredentials.tokenUrl = metadata.token_endpoint
if (
flows.clientCredentials
and scopes
and not flows.clientCredentials.scopes
):
flows.clientCredentials.scopes = scopes
if flows.authorizationCode and not flows.authorizationCode.authorizationUrl:
flows.authorizationCode.authorizationUrl = metadata.authorization_endpoint
if flows.authorizationCode and not flows.authorizationCode.tokenUrl:
flows.authorizationCode.tokenUrl = metadata.token_endpoint
if (
flows.authorizationCode
and scopes
and not flows.authorizationCode.scopes
):
flows.authorizationCode.scopes = scopes
return True

def _missing_oauth_info(self) -> bool:
Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/auth/test_credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ async def test_populate_auth_scheme_success(
manager._auth_config.auth_scheme.flows.authorizationCode.tokenUrl
== "https://auth.example.com/token"
)
assert manager._auth_config.auth_scheme.flows.authorizationCode.scopes == {
"read": "",
"write": "",
}

@pytest.mark.asyncio
async def test_populate_auth_scheme_fail(self, extended_oauth2_scheme):
Expand Down
Loading