-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathlambda_auth.js
More file actions
51 lines (51 loc) · 1.49 KB
/
lambda_auth.js
File metadata and controls
51 lines (51 loc) · 1.49 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
42
43
44
45
46
47
48
49
50
51
exports.handler = (event, context, callback) => {
console.log(event)
if (event.headers.authorization === "secretToken" || event.headers.Authorization === "secretToken") {
console.log("allowed");
let policy = {
"principalId": "abcdef", // The principal user identification associated with the token sent by the client.
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": event["methodArn"]
}
]
},
"context": {
"accountAlias": "account-alias",
"accountId": "12345-2345",
"permissions": "all-perms",
"projectId": "project-1234",
"tenantId": "tenant-1234",
"userId": "user-1234",
"stringKey": "value",
"numberKey": 1,
"booleanKey": true
}
};
console.log("policy: ", JSON.stringify(policy));
callback(null, policy);
} else {
console.log("denied");
let policy = {
"principalId": "abcdef", // The principal user identification associated with the token sent by the client.
"policyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Action": "execute-api:Invoke",
"Effect": "Deny",
"Resource": event["methodArn"]
}]
},
"context": {
"stringKey": "value",
"numberKey": 1,
"booleanKey": true
}
};
callback(null, policy);
}
};