azurite
Version:
An open source Azure Storage API compatible server
42 lines • 1.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const TableStorageContext_1 = tslib_1.__importDefault(require("../context/TableStorageContext"));
const StorageErrorFactory_1 = tslib_1.__importDefault(require("../errors/StorageErrorFactory"));
const ExpressRequestAdapter_1 = tslib_1.__importDefault(require("../generated/ExpressRequestAdapter"));
const constants_1 = require("../utils/constants");
class AuthenticationMiddlewareFactory {
constructor(logger) {
this.logger = logger;
}
createAuthenticationMiddleware(authenticators) {
return (req, res, next) => {
const context = new TableStorageContext_1.default(res.locals, constants_1.DEFAULT_TABLE_CONTEXT_PATH);
this.authenticate(req, res, authenticators)
.then((pass) => {
if (pass) {
next();
}
else {
next(StorageErrorFactory_1.default.getAuthorizationFailure(context));
}
})
.catch(next);
};
}
async authenticate(req, res, authenticators) {
const request = new ExpressRequestAdapter_1.default(req);
const context = new TableStorageContext_1.default(res.locals, constants_1.DEFAULT_TABLE_CONTEXT_PATH);
this.logger.verbose(`AuthenticationMiddlewareFactory:createAuthenticationMiddleware() Validating authentications.`, context.contextID);
let pass = false;
for (const authenticator of authenticators) {
pass = await authenticator.validate(request, context);
if (pass === true) {
return true;
}
}
return false;
}
}
exports.default = AuthenticationMiddlewareFactory;
//# sourceMappingURL=AuthenticationMiddlewareFactory.js.map
;