fix: Unable to acquire impersonated credentials

Merge https://github.com/google/adk-python/pull/2003

add scope "https://www.googleapis.com/auth/cloud-platform" within google.auth.default

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/2003 from hsuyuming:fix/issue_2001_support_impersonated_credential 8874a367273aca98460f7f250bfc4690f883ebbe
PiperOrigin-RevId: 788656025
This commit is contained in:
hsuyuming
2025-07-29 16:42:25 -07:00
committed by Copybara-Service
parent de6ebddcd2
commit 9db5d9a3e8
10 changed files with 238 additions and 8 deletions
@@ -604,11 +604,15 @@ class TestConnectionsClient:
mock.patch(
"google.adk.tools.application_integration_tool.clients.connections_client.default_service_credential",
return_value=(mock_credentials, "test_project_id"),
),
) as mock_default_service_credential,
mock.patch.object(mock_credentials, "refresh", return_value=None),
):
token = client._get_access_token()
assert token == "test_token"
# Verify default_service_credential is called with the correct scopes parameter
mock_default_service_credential.assert_called_once_with(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
def test_get_access_token_no_valid_credentials(
self, project, location, connection_name
@@ -537,7 +537,7 @@ class TestIntegrationClient:
mock.patch(
"google.adk.tools.application_integration_tool.clients.integration_client.default_service_credential",
return_value=(mock_credentials, "test_project_id"),
),
) as mock_default_service_credential,
mock.patch.object(mock_credentials, "refresh", return_value=None),
):
client = IntegrationClient(
@@ -552,6 +552,10 @@ class TestIntegrationClient:
)
token = client._get_access_token()
assert token == "test_token"
# Verify default_service_credential is called with the correct scopes parameter
mock_default_service_credential.assert_called_once_with(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
def test_get_access_token_no_valid_credentials(
self, project, location, integration_name, triggers, connection_name