Created
July 5, 2022 17:14
-
-
Save kevinjnguyen/87c7a009a76a7032cdb48b4c899f3b5c to your computer and use it in GitHub Desktop.
Lambda handler to parse the Segment Authorization Headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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