34
34
from google .auth import _helpers
35
35
from google .auth import credentials
36
36
from google .auth import exceptions
37
+ from google .auth import iam
37
38
from google .auth import jwt
38
39
from google .auth import metrics
39
40
40
- _IAM_SCOPE = ["https://www.googleapis.com/auth/iam" ]
41
-
42
- _IAM_ENDPOINT = (
43
- "https://iamcredentials.googleapis.com/v1/projects/-"
44
- + "/serviceAccounts/{}:generateAccessToken"
45
- )
46
-
47
- _IAM_SIGN_ENDPOINT = (
48
- "https://iamcredentials.googleapis.com/v1/projects/-"
49
- + "/serviceAccounts/{}:signBlob"
50
- )
51
-
52
- _IAM_IDTOKEN_ENDPOINT = (
53
- "https://iamcredentials.googleapis.com/v1/"
54
- + "projects/-/serviceAccounts/{}:generateIdToken"
55
- )
56
41
57
42
_REFRESH_ERROR = "Unable to acquire impersonated credentials"
58
43
59
44
_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds
60
45
61
- _DEFAULT_TOKEN_URI = "https://oauth2.googleapis.com/token"
62
-
63
46
64
47
def _make_iam_token_request (
65
48
request , principal , headers , body , iam_endpoint_override = None
@@ -83,7 +66,7 @@ def _make_iam_token_request(
83
66
`iamcredentials.googleapis.com` is not enabled or the
84
67
`Service Account Token Creator` is not assigned
85
68
"""
86
- iam_endpoint = iam_endpoint_override or _IAM_ENDPOINT .format (principal )
69
+ iam_endpoint = iam_endpoint_override or iam . _IAM_ENDPOINT .format (principal )
87
70
88
71
body = json .dumps (body ).encode ("utf-8" )
89
72
@@ -225,7 +208,9 @@ def __init__(
225
208
# added to refresh correctly. User credentials cannot have
226
209
# their original scopes modified.
227
210
if isinstance (self ._source_credentials , credentials .Scoped ):
228
- self ._source_credentials = self ._source_credentials .with_scopes (_IAM_SCOPE )
211
+ self ._source_credentials = self ._source_credentials .with_scopes (
212
+ iam ._IAM_SCOPE
213
+ )
229
214
# If the source credential is service account and self signed jwt
230
215
# is needed, we need to create a jwt credential inside it
231
216
if (
@@ -290,7 +275,7 @@ def _update_token(self, request):
290
275
def sign_bytes (self , message ):
291
276
from google .auth .transport .requests import AuthorizedSession
292
277
293
- iam_sign_endpoint = _IAM_SIGN_ENDPOINT .format (self ._target_principal )
278
+ iam_sign_endpoint = iam . _IAM_SIGN_ENDPOINT .format (self ._target_principal )
294
279
295
280
body = {
296
281
"payload" : base64 .b64encode (message ).decode ("utf-8" ),
@@ -425,7 +410,7 @@ def with_quota_project(self, quota_project_id):
425
410
def refresh (self , request ):
426
411
from google .auth .transport .requests import AuthorizedSession
427
412
428
- iam_sign_endpoint = _IAM_IDTOKEN_ENDPOINT .format (
413
+ iam_sign_endpoint = iam . _IAM_IDTOKEN_ENDPOINT .format (
429
414
self ._target_credentials .signer_email
430
415
)
431
416
0 commit comments