-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
57 lines (50 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const generatePolicy = function(principalId, effect, resource) {
const authResponse = {};
authResponse.principalId = principalId;
if (effect && resource) {
const policyDocument = {};
policyDocument.Version = '2012-10-17';
policyDocument.Statement = [];
const statementOne = {};
statementOne.Action = 'execute-api:Invoke';
statementOne.Effect = effect;
statementOne.Resource = resource;
policyDocument.Statement[0] = statementOne;
authResponse.policyDocument = policyDocument;
}
return authResponse;
};
module.exports.profile = (event, context, callback) => {
const body = {
message: 'Successs - Profile Retrieved!',
input: event,
};
const response = {
statusCode: 200,
body: JSON.stringify(body),
};
callback(null, response);
};
module.exports.auth = (event, context, callback) => {
var token = event.authorizationToken;
/*
*
* extra custom authorization logic here: OAUTH, JWT ... etc
*
*/
// In this example, the token is treated as the status for simplicity.
switch (token) {
case 'allow':
callback(null, generatePolicy('user', 'Allow', event.methodArn));
break;
case 'deny':
callback(null, generatePolicy('user', 'Deny', event.methodArn));
break;
case 'unauthorized':
callback('Unauthorized');
break;
default:
callback('Error');
}
};