Skip to content

Commit

Permalink
Update auth.js
Browse files Browse the repository at this point in the history
  • Loading branch information
arielweinberger authored Apr 29, 2020
1 parent a6b91e1 commit aca2d5c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/handlers/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import jwt from 'jsonwebtoken';

const generatePolicy = principalId => {
// By default, API Gateway authorizations are cached (TTL) for 300 seconds.
// This policy will authorize all requests to the same API Gateway instance where the
// request is coming from, thus being efficient and optimising costs.
const generatePolicy = (principalId, methodArn) => {
const apiGatewayWildcard = methodArn.split('/', 2).join('/') + '/*';
console.log('methodArn', methodArn);
console.log('apiGatewayWildcard', apiGatewayWildcard);

return {
principalId,
policyDocument: {
Expand All @@ -16,7 +23,7 @@ const generatePolicy = principalId => {
};
};

export function handler(event) {
export async function handler(event, context) {
if (!event.authorizationToken) {
throw 'Unauthorized';
}
Expand Down

0 comments on commit aca2d5c

Please sign in to comment.