n8n
Version:
n8n Workflow Automation Tool
19 lines • 828 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBearerToken = getBearerToken;
const bad_request_error_1 = require("../../errors/response-errors/bad-request.error");
const unauthenticated_error_1 = require("../../errors/response-errors/unauthenticated.error");
const BEARER_TOKEN_REGEX = /^[Bb][Ee][Aa][Rr][Ee][Rr]\s+(.+)$/;
function getBearerToken(req) {
const headerValue = req.headers['authorization']?.toString();
if (!headerValue) {
throw new unauthenticated_error_1.UnauthenticatedError();
}
const result = BEARER_TOKEN_REGEX.exec(headerValue);
const token = result ? result[1] : null;
if (!token) {
throw new bad_request_error_1.BadRequestError('Authorization header is malformed');
}
return token;
}
//# sourceMappingURL=utils.js.map