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/1dc68e12997e73256c81c74549a9cf6b to your computer and use it in GitHub Desktop.
Save tylertreat/1dc68e12997e73256c81c74549a9cf6b to your computer and use it in GitHub Desktop.
GCP OIDC proxy URL creation portion of handle_request
def handle_request(proxied_request):
"""Proxy the given request to the URL in the Forward-Host header with an
Authorization header set using an OIDC bearer token for the Cloud
Function's service account. If the header is not present, return a 400
error.
"""
host = proxied_request.headers.get(HOST_HEADER)
if not host:
return 'Required header {} not present'.format(HOST_HEADER), 400
scheme = proxied_request.headers.get('X-Forwarded-Proto', 'https')
url = '{}://{}{}'.format(scheme, host, proxied_request.path)
headers = dict(proxied_request.headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment