mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
30 lines
600 B
JavaScript
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)
|
||
|
}))
|
||
|
}
|