Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. exports.handler = (event, context, callback) => {
  2. const token = event.authorizationToken;
  3. // Use token
  4. if (token === 'allow') {
  5. const policy = genPolicy('allow', event.methodArn);
  6. const principalId = 'aflaf78fd7afalnv';
  7. const context = {
  8. simpleAuth: true
  9. };
  10. const response = {
  11. principalId: principalId,
  12. policyDocument: policy,
  13. context: context
  14. };
  15. callback(null, response);
  16. } else if (token == 'deny') {
  17. const policy = genPolicy('deny', event.methodArn);
  18. const principalId = 'aflaf78fd7afalnv';
  19. const context = {
  20. simpleAuth: true
  21. };
  22. const response = {
  23. principalId: principalId,
  24. policyDocument: policy,
  25. context: context
  26. };
  27. callback(null, response);
  28. } else {
  29. callback('Unauthorized');
  30. }
  31. };
  32.  
  33. function genPolicy(effect, resource) {
  34. const policy = {};
  35. policy.Version = '2012-10-17';
  36. policy.Statement = [];
  37. const stmt = {};
  38. stmt.Action = 'execute-api:Invoke';
  39. stmt.Effect = effect;
  40. stmt.Resource = resource;
  41. policy.Statement.push(stmt);
  42. return policy;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement