MCPcopy Create free account
hub / github.com/serverless/examples / generatePolicy

Function generatePolicy

aws-node-auth0-cognito-custom-authorizers-api/auth.js:14–29  ·  view source on GitHub ↗
(principalId, effect, resource)

Source from the content-addressed store, hash-verified

12
13// Generate policy to allow this user on this API:
14const generatePolicy = (principalId, effect, resource) => {
15 const authResponse = {};
16 authResponse.principalId = principalId;
17 if (effect && resource) {
18 const policyDocument = {};
19 policyDocument.Version = '2012-10-17';
20 policyDocument.Statement = [];
21 const statementOne = {};
22 statementOne.Action = 'execute-api:Invoke';
23 statementOne.Effect = effect;
24 statementOne.Resource = resource;
25 policyDocument.Statement[0] = statementOne;
26 authResponse.policyDocument = policyDocument;
27 }
28 return authResponse;
29};
30
31// Reusable Authorizer function, set on `authorizer` field in serverless.yml
32module.exports.authorize = (event, context, cb) => {

Callers 1

auth.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected