Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2023 18:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Imagin Games - API Gateway authorizer lambda source code
import os
import jwt
def decode_authorization_header(identity_source: list) -> dict:
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:
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