UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

67 lines (49 loc) 1.57 kB
var Client, Q, SDC, application, auth, config, crypto, domain, logger, os, sdc, statsdServer; auth = require('basic-auth'); Q = require("q"); Client = require("../model/clients").Client; logger = require("winston"); crypto = require("crypto"); config = require('../config/config'); statsdServer = config.get('statsd'); application = config.get('application'); SDC = require('statsd-client'); os = require('os'); domain = (os.hostname()) + "." + application.name + ".appMetrics"; sdc = new SDC(statsdServer); exports.authenticateUser = function(ctx, done) { return Client.findOne({ _id: ctx.request.header.clientid }, function(err, client) { 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 */ exports.koaMiddleware = function*(next) { var authenticateUser, startTime; if (statsdServer.enabled) { startTime = new Date(); } authenticateUser = Q.denodeify(exports.authenticateUser); (yield authenticateUser(this)); if (this.authenticated != null) { if (statsdServer.enabled) { sdc.timing(domain + ".rerunBypassAuthenticationMiddleware", startTime); } return (yield next); } else { this.authenticated = { ip: '127.0.0.1' }; if (statsdServer.enabled) { sdc.timing(domain + ".rerunBypassAuthenticationMiddleware", startTime); } return (yield next); } }; //# sourceMappingURL=rerunBypassAuthentication.js.map