forked from Triple-Take-Technologies/aws_gw_lambda_simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws-auth.js
More file actions
41 lines (36 loc) · 1.19 KB
/
ws-auth.js
File metadata and controls
41 lines (36 loc) · 1.19 KB
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
module.exports = {
handler: async (event, context) => {
const username = event.queryStringParameters['username'];
if (username) {
return generateAllow(`ab.c`, event.methodArn, {
providerName : 'ab',
username
});
}
else {
return null;
}
}
}
// Help function to generate an IAM policy
var generatePolicy = function (principalId, effect, resource, data) {
// Required output:
var authResponse = {};
authResponse.principalId = principalId;
if (effect && resource) {
var policyDocument = {};
policyDocument.Version = '2012-10-17'; // default version
policyDocument.Statement = [];
var statementOne = {};
statementOne.Action = 'execute-api:Invoke'; // default action
statementOne.Effect = effect;
statementOne.Resource = resource;
policyDocument.Statement[0] = statementOne;
authResponse.policyDocument = policyDocument;
}
authResponse.context = data;
return authResponse;
}
var generateAllow = function (principalId, resource, data) {
return generatePolicy(principalId, 'Allow', resource, data);
}