@@ -117,7 +117,7 @@ class Credentials(credentials.Signing,
117117 """
118118
119119 def __init__ (self , signer , service_account_email , token_uri , scopes = None ,
120- subject = None , additional_claims = None ):
120+ subject = None , project_id = None , additional_claims = None ):
121121 """
122122 Args:
123123 signer (google.auth.crypt.Signer): The signer used to sign JWTs.
@@ -127,6 +127,8 @@ def __init__(self, signer, service_account_email, token_uri, scopes=None,
127127 token_uri (str): The OAuth 2.0 Token URI.
128128 subject (str): For domain-wide delegation, the email address of the
129129 user to for which to request delegated access.
130+ project_id (str): Project ID associated with the service account
131+ credential.
130132 additional_claims (Mapping[str, str]): Any additional claims for
131133 the JWT assertion used in the authorization grant.
132134
@@ -141,6 +143,7 @@ def __init__(self, signer, service_account_email, token_uri, scopes=None,
141143 self ._signer = signer
142144 self ._service_account_email = service_account_email
143145 self ._subject = subject
146+ self ._project_id = project_id
144147 self ._token_uri = token_uri
145148
146149 if additional_claims is not None :
@@ -167,7 +170,8 @@ def _from_signer_and_info(cls, signer, info, **kwargs):
167170 return cls (
168171 signer ,
169172 service_account_email = info ['client_email' ],
170- token_uri = info ['token_uri' ], ** kwargs )
173+ token_uri = info ['token_uri' ],
174+ project_id = info .get ('project_id' ), ** kwargs )
171175
172176 @classmethod
173177 def from_service_account_info (cls , info , ** kwargs ):
@@ -210,6 +214,11 @@ def service_account_email(self):
210214 """The service account email."""
211215 return self ._service_account_email
212216
217+ @property
218+ def project_id (self ):
219+ """Project ID associated with this credential."""
220+ return self ._project_id
221+
213222 @property
214223 def requires_scopes (self ):
215224 """Checks if the credentials requires scopes.
@@ -227,6 +236,7 @@ def with_scopes(self, scopes):
227236 scopes = scopes ,
228237 token_uri = self ._token_uri ,
229238 subject = self ._subject ,
239+ project_id = self ._project_id ,
230240 additional_claims = self ._additional_claims .copy ())
231241
232242 def with_subject (self , subject ):
@@ -245,6 +255,7 @@ def with_subject(self, subject):
245255 scopes = self ._scopes ,
246256 token_uri = self ._token_uri ,
247257 subject = subject ,
258+ project_id = self ._project_id ,
248259 additional_claims = self ._additional_claims .copy ())
249260
250261 def with_claims (self , additional_claims ):
@@ -268,6 +279,7 @@ def with_claims(self, additional_claims):
268279 scopes = self ._scopes ,
269280 token_uri = self ._token_uri ,
270281 subject = self ._subject ,
282+ project_id = self ._project_id ,
271283 additional_claims = new_additional_claims )
272284
273285 def _make_authorization_grant_assertion (self ):
0 commit comments