3434from google .auth import _helpers
3535from google .auth import credentials
3636from google .auth import exceptions
37+ from google .auth import iam
3738from google .auth import jwt
3839from google .auth import metrics
3940
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- )
5641
5742_REFRESH_ERROR = "Unable to acquire impersonated credentials"
5843
5944_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds
6045
61- _DEFAULT_TOKEN_URI = "https://oauth2.googleapis.com/token"
62-
6346
6447def _make_iam_token_request (
6548 request , principal , headers , body , iam_endpoint_override = None
@@ -83,7 +66,7 @@ def _make_iam_token_request(
8366 `iamcredentials.googleapis.com` is not enabled or the
8467 `Service Account Token Creator` is not assigned
8568 """
86- iam_endpoint = iam_endpoint_override or _IAM_ENDPOINT .format (principal )
69+ iam_endpoint = iam_endpoint_override or iam . _IAM_ENDPOINT .format (principal )
8770
8871 body = json .dumps (body ).encode ("utf-8" )
8972
@@ -225,7 +208,9 @@ def __init__(
225208 # added to refresh correctly. User credentials cannot have
226209 # their original scopes modified.
227210 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+ )
229214 # If the source credential is service account and self signed jwt
230215 # is needed, we need to create a jwt credential inside it
231216 if (
@@ -290,7 +275,7 @@ def _update_token(self, request):
290275 def sign_bytes (self , message ):
291276 from google .auth .transport .requests import AuthorizedSession
292277
293- iam_sign_endpoint = _IAM_SIGN_ENDPOINT .format (self ._target_principal )
278+ iam_sign_endpoint = iam . _IAM_SIGN_ENDPOINT .format (self ._target_principal )
294279
295280 body = {
296281 "payload" : base64 .b64encode (message ).decode ("utf-8" ),
@@ -425,7 +410,7 @@ def with_quota_project(self, quota_project_id):
425410 def refresh (self , request ):
426411 from google .auth .transport .requests import AuthorizedSession
427412
428- iam_sign_endpoint = _IAM_IDTOKEN_ENDPOINT .format (
413+ iam_sign_endpoint = iam . _IAM_IDTOKEN_ENDPOINT .format (
429414 self ._target_credentials .signer_email
430415 )
431416
0 commit comments