Skip to content

Instantly share code, notes, and snippets.

@alexishida
Created January 27, 2022 22:53
Show Gist options
  • Select an option

  • Save alexishida/269fb135591cea1d5f2e70cd7a10e829 to your computer and use it in GitHub Desktop.

Select an option

Save alexishida/269fb135591cea1d5f2e70cd7a10e829 to your computer and use it in GitHub Desktop.
jwt authorizer aws api gateway
https://medium.com/swlh/how-to-protect-apis-with-jwt-and-api-gateway-lambda-authorizer-1110ff035df1
https://github.com/alexishida/lambda-authorizers-collections
exports.handler = async (event) => {
if(event.authorizationToken === "OK")
return allowPolicy(event.methodArn);
return denyAllPolicy();
};
function denyAllPolicy(){
return {
"principalId": "*",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "*",
"Effect": "Deny",
"Resource": "*"
}
]
}
}
}
function allowPolicy(methodArn){
return {
"principalId": "apigateway.amazonaws.com",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": methodArn
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment