Skip to content

Instantly share code, notes, and snippets.

@tylertreat
Last active January 29, 2019 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylertreat/e6e8f1fcd95d29e2f804fbee631bdf4b to your computer and use it in GitHub Desktop.
Save tylertreat/e6e8f1fcd95d29e2f804fbee631bdf4b to your computer and use it in GitHub Desktop.
GCP OIDC proxy send request
global _oidc_token
if not _oidc_token or _oidc_token.is_expired():
_oidc_token = _get_google_oidc_token()
logging.info('Renewed OIDC bearer token for {}'.format(
_adc_credentials.service_account_email))
# Add the Authorization header with the OIDC token.
headers['Authorization'] = 'Bearer {}'.format(_oidc_token)
# We don't want to forward the Host header.
headers.pop('Host', None)
request = Request(proxied_request.method, url,
headers=headers,
data=proxied_request.data)
# Send the proxied request.
prepped = request.prepare()
logging.info('{} {}'.format(prepped.method, prepped.url))
resp = _session.send(prepped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment