openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
48 lines (38 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.authoriseUser = authoriseUser;
exports.koaMiddleware = koaMiddleware;
var _channels = require("../model/channels");
var _transactions = require("../model/transactions");
var _config = require("../config");
var _util = require("util");
function authoriseUser(ctx, done) {
// Use the original transaction's channel to setup the authorised channel
_transactions.TransactionModel.findOne({
_id: ctx.parentID
}, (err, originalTransaction) => {
if (err) {
return done(err);
}
_channels.ChannelModel.findOne({
_id: originalTransaction.channelID
}, (err, authorisedChannel) => {
if (err) {
return done(err);
}
ctx.authorisedChannel = authorisedChannel;
return done();
});
});
}
/*
* Koa middleware for authentication by basic auth
*/
async function koaMiddleware(ctx, next) {
const authoriseUser = (0, _util.promisify)(exports.authoriseUser);
await authoriseUser(ctx);
await next();
}
//# sourceMappingURL=rerunBypassAuthorisation.js.map