-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (22 loc) · 808 Bytes
/
Copy pathindex.js
File metadata and controls
24 lines (22 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
exports.handler = async (event) => {
let isAllowedAccess = false;
const request = event.Records[0].cf.request;
if (request && request.headers && request.headers.authorization) {
const basicAuthHeader = request.headers.authorization[0].value;
const authString = 'Basic ' + new Buffer('__USERNAME___TO_BE_REPLACED' + ':' + '__PASSWORD__TO_BE_REPLACED').toString('base64');
isAllowedAccess = (basicAuthHeader === authString)
}
if (!isAllowedAccess) {
const response = {
status: 401,
body: JSON.stringify('Restricted area!'),
headers: {
'www-authenticate':[{ key: 'WWW-Authenticate', value: 'Basic'}]
},
};
return response;
}
else {
return request;
}
};