Skip to content

Instantly share code, notes, and snippets.

@sunghun7511
Created June 26, 2023 18:41
Show Gist options
  • Save sunghun7511/f92a24c31d2690b7509717a36d8327d1 to your computer and use it in GitHub Desktop.
Save sunghun7511/f92a24c31d2690b7509717a36d8327d1 to your computer and use it in GitHub Desktop.
Imagin Games - API Gateway authorizer lambda source code
import os
import jwt
def decode_authorization_header(identity_source: list) -> dict:
try:
token = identity_source[0].split(" ")[1]
key = os.environ.get("JWT_TOKEN")
result = jwt.decode(token, key, algorithms="HS256")
if "id" in result:
return result
except Exception:
pass
return None
def lambda_handler(event, context):
decoded = decode_authorization_header(event.get("identitySource", []))
if decoded is not None and "id" in decoded:
return {"isAuthorized": True, "context": decoded}
return {"isAuthorized": False}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment