Skip to content

Commit 4fec9d0

Browse files
committed
fix: Read scopes from ADC json for impersoanted cred
1 parent 36ecb1d commit 4fec9d0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

google/auth/impersonated_credentials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def from_impersonated_service_account_info(cls, info, scopes=None):
526526
target_principal = impersonation_url[start_index + 1 : end_index]
527527
delegates = info.get("delegates")
528528
quota_project_id = info.get("quota_project_id")
529+
scopes = scopes or info.get("scopes")
529530
trust_boundary = info.get("trust_boundary")
530531

531532
return cls(

tests/test_impersonated_credentials.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,27 @@ def test_from_impersonated_service_account_info_with_invalid_impersonation_url(
213213
)
214214
assert excinfo.match(r"Cannot extract target principal from")
215215

216+
def test_from_impersonated_service_account_info_with_scopes(self):
217+
info = copy.deepcopy(IMPERSONATED_SERVICE_ACCOUNT_AUTHORIZED_USER_SOURCE_INFO)
218+
info["scopes"] = ["scope1", "scope2"]
219+
credentials = (
220+
impersonated_credentials.Credentials.from_impersonated_service_account_info(
221+
info
222+
)
223+
)
224+
assert credentials._target_scopes == ["scope1", "scope2"]
225+
226+
def test_from_impersonated_service_account_info_with_scopes_param(self):
227+
info = copy.deepcopy(IMPERSONATED_SERVICE_ACCOUNT_AUTHORIZED_USER_SOURCE_INFO)
228+
info["scopes"] = ["scope_from_info_1", "scope_from_info_2"]
229+
scopes_param = ["scope_from_param_1", "scope_from_param_2"]
230+
credentials = (
231+
impersonated_credentials.Credentials.from_impersonated_service_account_info(
232+
info, scopes=scopes_param
233+
)
234+
)
235+
assert credentials._target_scopes == scopes_param
236+
216237
def test_get_cred_info(self):
217238
credentials = self.make_credentials()
218239
assert not credentials.get_cred_info()

0 commit comments

Comments
 (0)