@@ -327,6 +327,7 @@ def call_iam_generate_id_token_endpoint(
327
327
signer_email ,
328
328
audience ,
329
329
access_token ,
330
+ headers = None ,
330
331
universe_domain = credentials .DEFAULT_UNIVERSE_DOMAIN ,
331
332
):
332
333
"""Call iam.generateIdToken endpoint to get ID token.
@@ -339,6 +340,9 @@ def call_iam_generate_id_token_endpoint(
339
340
generateIdToken endpoint.
340
341
audience (str): The audience for the ID token.
341
342
access_token (str): The access token used to call the IAM endpoint.
343
+ headers (Optional[Mapping[str, str]]): The headers for the request.
344
+ universe_domain (str): The universe domain for the request. The
345
+ default is ``googleapis.com``.
342
346
343
347
Returns:
344
348
Tuple[str, datetime]: The ID token and expiration.
@@ -353,6 +357,7 @@ def call_iam_generate_id_token_endpoint(
353
357
body ,
354
358
access_token = access_token ,
355
359
use_json = True ,
360
+ headers = headers ,
356
361
)
357
362
358
363
try :
@@ -510,7 +515,7 @@ def refresh_grant(
510
515
return _handle_refresh_grant_response (response_data , refresh_token )
511
516
512
517
513
- def lookup_trust_boundary (request , url , access_token ):
518
+ def lookup_trust_boundary (request , url , headers = None ):
514
519
"""Implements the global lookup of a credential trust boundary.
515
520
For the lookup, we send a request to the global lookup endpoint and then
516
521
parse the response. Service account credentials, workload identity
@@ -519,15 +524,7 @@ def lookup_trust_boundary(request, url, access_token):
519
524
request (google.auth.transport.Request): A callable used to make
520
525
HTTP requests.
521
526
url (str): The trust boundary lookup url.
522
- access_token (Optional(str)): The access token needed to make the request
523
527
headers (Optional[Mapping[str, str]]): The headers for the request.
524
- kwargs: Additional arguments passed on to the request method. The
525
- kwargs will be passed to `requests.request` method, see:
526
- https://docs.python-requests.org/en/latest/api/#requests.request.
527
- For example, you can use `cert=("cert_pem_path", "key_pem_path")`
528
- to set up client side SSL certificate, and use
529
- `verify="ca_bundle_path"` to set up the CA certificates for sever
530
- side SSL certificate verification.
531
528
Returns:
532
529
Mapping[str,list|str]: A dictionary containing
533
530
"locations" as a list of allowed locations as strings and
@@ -550,7 +547,7 @@ def lookup_trust_boundary(request, url, access_token):
550
547
exceptions.MalformedError: If the response is not in a valid format.
551
548
"""
552
549
553
- response_data = _lookup_trust_boundary_request (request , url , access_token , True )
550
+ response_data = _lookup_trust_boundary_request (request , url , headers = headers )
554
551
# In case of no-op response, the "locations" list may or may not be present as an empty list.
555
552
if "encodedLocations" not in response_data :
556
553
raise exceptions .MalformedError (
@@ -560,16 +557,16 @@ def lookup_trust_boundary(request, url, access_token):
560
557
561
558
562
559
def _lookup_trust_boundary_request (
563
- request , url , access_token , can_retry = True , ** kwargs
560
+ request , url , can_retry = True , headers = None , ** kwargs
564
561
):
565
562
"""Makes a request to the trust boundary lookup endpoint.
566
563
567
564
Args:
568
565
request (google.auth.transport.Request): A callable used to make
569
566
HTTP requests.
570
567
url (str): The trust boundary lookup url.
571
- access_token (Optional(str)): The access token needed to make the request
572
568
can_retry (bool): Enable or disable request retry behavior. Defaults to true.
569
+ headers (Optional[Mapping[str, str]]): The headers for the request.
573
570
kwargs: Additional arguments passed on to the request method. The
574
571
kwargs will be passed to `requests.request` method, see:
575
572
https://docs.python-requests.org/en/latest/api/#requests.request.
@@ -587,7 +584,7 @@ def _lookup_trust_boundary_request(
587
584
"""
588
585
response_status_ok , response_data , retryable_error = (
589
586
_lookup_trust_boundary_request_no_throw (
590
- request , url , access_token = access_token , can_retry = can_retry , ** kwargs
587
+ request , url , can_retry , headers , ** kwargs
591
588
)
592
589
)
593
590
if not response_status_ok :
@@ -596,7 +593,7 @@ def _lookup_trust_boundary_request(
596
593
597
594
598
595
def _lookup_trust_boundary_request_no_throw (
599
- request , url , access_token = None , can_retry = True , ** kwargs
596
+ request , url , can_retry = True , headers = None , ** kwargs
600
597
):
601
598
"""Makes a request to the trust boundary lookup endpoint. This
602
599
function doesn't throw on response errors.
@@ -605,8 +602,8 @@ def _lookup_trust_boundary_request_no_throw(
605
602
request (google.auth.transport.Request): A callable used to make
606
603
HTTP requests.
607
604
url (str): The trust boundary lookup url.
608
- access_token (Optional(str)): The access token needed to make the request
609
605
can_retry (bool): Enable or disable request retry behavior. Defaults to true.
606
+ headers (Optional[Mapping[str, str]]): The headers for the request.
610
607
kwargs: Additional arguments passed on to the request method. The
611
608
kwargs will be passed to `requests.request` method, see:
612
609
https://docs.python-requests.org/en/latest/api/#requests.request.
@@ -622,14 +619,12 @@ def _lookup_trust_boundary_request_no_throw(
622
619
is retryable.
623
620
"""
624
621
625
- headers_to_use = {"Authorization" : "Bearer {}" .format (access_token )}
626
-
627
622
response_data = {}
628
623
retryable_error = False
629
624
630
625
retries = _exponential_backoff .ExponentialBackoff ()
631
626
for _ in retries :
632
- response = request (method = "GET" , url = url , headers = headers_to_use , ** kwargs )
627
+ response = request (method = "GET" , url = url , headers = headers , ** kwargs )
633
628
response_body = (
634
629
response .data .decode ("utf-8" )
635
630
if hasattr (response .data , "decode" )
0 commit comments