Skip to content

Instantly share code, notes, and snippets.

@kevinjnguyen
Created July 5, 2022 17:14
Show Gist options
  • Save kevinjnguyen/87c7a009a76a7032cdb48b4c899f3b5c to your computer and use it in GitHub Desktop.
Save kevinjnguyen/87c7a009a76a7032cdb48b4c899f3b5c to your computer and use it in GitHub Desktop.
Lambda handler to parse the Segment Authorization Headers
import base64
def lambda_handler(event, context):
assert 'headers' in event, 'missing headers'
assert 'authorization' in event['headers'], 'missing authorization header'
authorization_header: str = event['headers']['authorization']
authorization_tokens = authorization_header.split()
assert len(authorization_tokens) == 2, 'malformed authorization bearer token'
bearer_token = authorization_tokens[1]
api_key = base64.b64decode(bearer_token).decode("utf-8")[:-1] # Remove the last character added from padding
# Verify API Key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment