UNPKG

aws-apigw-authorizer

Version:
19 lines (18 loc) 706 B
"use strict"; 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;