Created
May 8, 2020 12:16
-
-
Save njofce/3382b0fe51c59ae9038046cd5087e42a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = async (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
const user = 'YOUR_USERNAME_HERE'; | |
const pass = 'YOUR_PASSWORD_HERE'; | |
const basicAuthentication = 'Basic ' + new Buffer(user + ':' + pass).toString('base64'); | |
if (typeof headers.authorization == 'undefined' || headers.authorization[0].value != basicAuthentication) { | |
const body = 'You are not authorized to enter'; | |
const response = { | |
status: '401', | |
statusDescription: 'Unauthorized', | |
body: body, | |
headers: { | |
'www-authenticate': [{key: 'WWW-Authenticate', value:'Basic'}] | |
}, | |
}; | |
callback(null, response); | |
} | |
callback(null, request); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment