openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
30 lines (25 loc) • 703 B
JavaScript
import { ClientModel } from '../model/clients'
import { config } from '../config'
import { promisify } from 'util'
const dummyClient = new ClientModel({
clientID: 'DUMMY-POLLING-USER',
clientDomain: 'openhim.org',
name: 'DUMMY-POLLING-USER',
roles: ['polling']
})
export function authenticateUser (ctx, done) {
ctx.authenticated = dummyClient
return done(null, dummyClient)
}
/*
* Koa middleware for bypassing authentication for polling requests
*/
export async function koaMiddleware (ctx, next) {
const _authenticateUser = promisify(authenticateUser)
await _authenticateUser(ctx)
if (ctx.authenticated != null) {
await next()
} else {
ctx.response.status = 401
}
}