arma-server-web-admin/lib/setup-basic-auth.js

30 lines
600 B
JavaScript
Raw Normal View History

2017-09-30 12:13:59 +00:00
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)
}))
}