arma-server-web-admin/lib/setup-basic-auth.js
2017-10-01 03:26:07 +02:00

30 lines
600 B
JavaScript

var basicAuth = require('express-basic-auth')
function getBasicAuthUsers (configAuth) {
var basicAuthUsers = {}
if (configAuth.username && configAuth.password) {
configAuth = [configAuth]
}
configAuth.forEach(function (user) {
basicAuthUsers[user.username] = user.password
})
return basicAuthUsers
}
module.exports = function (config, app) {
if (!config.auth) {
return
}
if (!config.auth.username && !config.auth.password && !Array.isArray(config.auth)) {
return
}
app.use(basicAuth({
challenge: true,
users: getBasicAuthUsers(config.auth)
}))
}