openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
49 lines (38 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.authenticateUser = authenticateUser;
exports.koaMiddleware = koaMiddleware;
var _clients = require("../model/clients");
var _config = require("../config");
var _util = require("util");
function authenticateUser(ctx, done) {
return _clients.ClientModel.findOne({
_id: ctx.request.header.clientid
}, (err, client) => {
if (err) {
return done(err);
}
ctx.authenticated = client;
ctx.parentID = ctx.request.header.parentid;
ctx.taskID = ctx.request.header.taskid;
return done(null, client);
});
}
/*
* Koa middleware for authentication by basic auth
*/
async function koaMiddleware(ctx, next) {
const _authenticateUser = (0, _util.promisify)(authenticateUser);
await _authenticateUser(ctx);
if (ctx.authenticated != null) {
await next();
} else {
ctx.authenticated = {
ip: '127.0.0.1'
}; // This is a public channel, allow rerun
await next();
}
}
//# sourceMappingURL=rerunBypassAuthentication.js.map