UNPKG

@leismore/authappself_handler

Version:

An Express.js HTTP handler of authentication and authorization services for self-owned LMOS (NodeJS) applications.

31 lines (30 loc) 879 B
"use strict"; /** * parse_httpAuth function: Parse HTTP Authorization header. * @throw {AASHError} */ Object.defineProperty(exports, "__esModule", { value: true }); exports.parse_httpAuth = void 0; const auth = require("basic-auth"); const AASHError_1 = require("./AASHError"); const ERROR = new AASHError_1.AASHError({ message: 'invalid credential', code: '1' }, { statusCode: '403' }); function parse_httpAuth(httpAuth) { let credential; let parsed = auth.parse(String(httpAuth)); if (parsed === undefined) { throw ERROR; } else { credential = { appID: parsed.name, token: parsed.pass }; if (credential.appID.length === 0 || credential.token.length === 0) { throw ERROR; } else { return credential; } } } exports.parse_httpAuth = parse_httpAuth;