@@ -87,6 +87,7 @@ def __init__(
87
87
granted_scopes = None ,
88
88
trust_boundary = None ,
89
89
universe_domain = _DEFAULT_UNIVERSE_DOMAIN ,
90
+ account = None ,
90
91
):
91
92
"""
92
93
Args:
@@ -131,6 +132,7 @@ def __init__(
131
132
trust_boundary (str): String representation of trust boundary meta.
132
133
universe_domain (Optional[str]): The universe domain. The default
133
134
universe domain is googleapis.com.
135
+ account (Optional[str]): The account associated with the credential.
134
136
"""
135
137
super (Credentials , self ).__init__ ()
136
138
self .token = token
@@ -149,6 +151,7 @@ def __init__(
149
151
self ._enable_reauth_refresh = enable_reauth_refresh
150
152
self ._trust_boundary = trust_boundary
151
153
self ._universe_domain = universe_domain or _DEFAULT_UNIVERSE_DOMAIN
154
+ self ._account = account or ""
152
155
153
156
def __getstate__ (self ):
154
157
"""A __getstate__ method must exist for the __setstate__ to be called
@@ -189,6 +192,7 @@ def __setstate__(self, d):
189
192
self ._refresh_handler = None
190
193
self ._refresh_worker = None
191
194
self ._use_non_blocking_refresh = d .get ("_use_non_blocking_refresh" , False )
195
+ self ._account = d .get ("_account" , "" )
192
196
193
197
@property
194
198
def refresh_token (self ):
@@ -268,6 +272,11 @@ def refresh_handler(self, value):
268
272
raise TypeError ("The provided refresh_handler is not a callable or None." )
269
273
self ._refresh_handler = value
270
274
275
+ @property
276
+ def account (self ):
277
+ """str: The user account associated with the credential. If the account is unknown an empty string is returned."""
278
+ return self ._account
279
+
271
280
@_helpers .copy_docstring (credentials .CredentialsWithQuotaProject )
272
281
def with_quota_project (self , quota_project_id ):
273
282
@@ -286,6 +295,7 @@ def with_quota_project(self, quota_project_id):
286
295
enable_reauth_refresh = self ._enable_reauth_refresh ,
287
296
trust_boundary = self ._trust_boundary ,
288
297
universe_domain = self ._universe_domain ,
298
+ account = self ._account ,
289
299
)
290
300
291
301
@_helpers .copy_docstring (credentials .CredentialsWithTokenUri )
@@ -306,6 +316,35 @@ def with_token_uri(self, token_uri):
306
316
enable_reauth_refresh = self ._enable_reauth_refresh ,
307
317
trust_boundary = self ._trust_boundary ,
308
318
universe_domain = self ._universe_domain ,
319
+ account = self ._account ,
320
+ )
321
+
322
+ def with_account (self , account ):
323
+ """Returns a copy of these credentials with a modified account.
324
+
325
+ Args:
326
+ account (str): The account to set
327
+
328
+ Returns:
329
+ google.oauth2.credentials.Credentials: A new credentials instance.
330
+ """
331
+
332
+ return self .__class__ (
333
+ self .token ,
334
+ refresh_token = self .refresh_token ,
335
+ id_token = self .id_token ,
336
+ token_uri = self ._token_uri ,
337
+ client_id = self .client_id ,
338
+ client_secret = self .client_secret ,
339
+ scopes = self .scopes ,
340
+ default_scopes = self .default_scopes ,
341
+ granted_scopes = self .granted_scopes ,
342
+ quota_project_id = self .quota_project_id ,
343
+ rapt_token = self .rapt_token ,
344
+ enable_reauth_refresh = self ._enable_reauth_refresh ,
345
+ trust_boundary = self ._trust_boundary ,
346
+ universe_domain = self ._universe_domain ,
347
+ account = account ,
309
348
)
310
349
311
350
@_helpers .copy_docstring (credentials .CredentialsWithUniverseDomain )
@@ -326,6 +365,7 @@ def with_universe_domain(self, universe_domain):
326
365
enable_reauth_refresh = self ._enable_reauth_refresh ,
327
366
trust_boundary = self ._trust_boundary ,
328
367
universe_domain = universe_domain ,
368
+ account = self ._account ,
329
369
)
330
370
331
371
def _metric_header_for_usage (self ):
@@ -474,6 +514,7 @@ def from_authorized_user_info(cls, info, scopes=None):
474
514
rapt_token = info .get ("rapt_token" ), # may not exist
475
515
trust_boundary = info .get ("trust_boundary" ), # may not exist
476
516
universe_domain = info .get ("universe_domain" ), # may not exist
517
+ account = info .get ("account" , "" ), # may not exist
477
518
)
478
519
479
520
@classmethod
@@ -518,6 +559,7 @@ def to_json(self, strip=None):
518
559
"scopes" : self .scopes ,
519
560
"rapt_token" : self .rapt_token ,
520
561
"universe_domain" : self ._universe_domain ,
562
+ "account" : self ._account ,
521
563
}
522
564
if self .expiry : # flatten expiry timestamp
523
565
prep ["expiry" ] = self .expiry .isoformat () + "Z"
0 commit comments