aws-apigw-authorizer
Version:
AWS Lambda Authorizer for API Gateway
19 lines (18 loc) • 706 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const auth = require('basic-auth');
function validate(token) {
const userObj = auth.parse(`Basic ${token}`);
if (!userObj) {
throw new Error(`Cannot parse Basic Auth token ${token}`);
}
const expectedPassword = process.env[`BASIC_AUTH_USER_${userObj.name}`];
if (!expectedPassword) {
throw new Error(`Unknown user ${userObj.name} trying to authenticate with Basic Auth`);
}
if (expectedPassword !== userObj.pass) {
throw new Error(`User ${userObj.name} password mismatch while trying to authenticatie with Basic Auth`);
}
return userObj;
}
exports.validate = validate;
;