@libj/http-meta
Version:
25 lines • 996 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseHttpBearerAuthToken = exports.makeHttpBearerAuth = void 0;
var HttpAuthScheme_1 = require("./HttpAuthScheme");
var error_1 = require("../../error");
var makeHttpBearerAuth = function (token) {
if (!token || !token.trim()) {
throw new Error('Bearer token is empty');
}
return "".concat(HttpAuthScheme_1.HttpAuthScheme.BEARER, " ").concat(token.trim());
};
exports.makeHttpBearerAuth = makeHttpBearerAuth;
var parseHttpBearerAuthToken = function (auth, options) {
if (options === void 0) { options = {}; }
var parts = auth && auth.split(HttpAuthScheme_1.HttpAuthScheme.BEARER);
if (parts && parts.length === 2 && parts[1].trim()) {
return parts[1].trim();
}
if (options.silent) {
return null;
}
throw new error_1.UnauthorizedHttpError();
};
exports.parseHttpBearerAuthToken = parseHttpBearerAuthToken;
//# sourceMappingURL=httpBearerAuth.js.map
;