Skip to content

Commit

Permalink
adding test file
Browse files Browse the repository at this point in the history
  • Loading branch information
MacAndersonUche committed Oct 4, 2023
1 parent 1a39f90 commit b84f2c6
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/authorizer/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { APIGatewayTokenAuthorizerEvent } from 'aws-lambda';

exports.handler = async function (event: APIGatewayTokenAuthorizerEvent) {
console.log(event);
// const token = event.authorizationToken;
// const { organisationId, userName } = decodeAccessToken(
// token.replace('Bearer ', '').replace('bearer ', '')
// );
const methodArn = event.methodArn;
// if (organisationId && userName) {
// return generateAuthResponse('user', 'Allow', methodArn);
// } else {
// return generateAuthResponse('user', 'Deny', methodArn);
// }

return generateAuthResponse('user', 'Allow', methodArn);
};

function generateAuthResponse(
principalId: string,
effect: string,
methodArn: string
) {
const policyDocument = generatePolicyDocument(effect, methodArn);

return {
principalId,
policyDocument,
};
}

function generatePolicyDocument(effect: string, methodArn: string) {
if (!effect || !methodArn) return null;

const policyDocument = {
Version: '2012-10-17',
Statement: [
{
Action: 'execute-api:Invoke',
Effect: effect,
Resource: methodArn,
},
],
};

return policyDocument;
}

0 comments on commit b84f2c6

Please sign in to comment.