From 12250a93f1e35a6c4f3b2753a05baa65eff9fb0e Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Tue, 4 Jun 2019 15:52:25 -0500 Subject: [PATCH] feat(basic-auth): allow multiple auth pairs (#11204) --- config.json.example | 4 ++-- website/server/middlewares/index.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.json.example b/config.json.example index 09b6778415..2c5e30fdf1 100644 --- a/config.json.example +++ b/config.json.example @@ -61,8 +61,8 @@ "SESSION_SECRET_IV": "12345678912345678912345678912345", "SESSION_SECRET_KEY": "1234567891234567891234567891234567891234567891234567891234567891", "SITE_HTTP_AUTH_ENABLED": "false", - "SITE_HTTP_AUTH_PASSWORD": "password", - "SITE_HTTP_AUTH_USERNAME": "admin", + "SITE_HTTP_AUTH_PASSWORDS": "password,wordpass,passkey", + "SITE_HTTP_AUTH_USERNAMES": "admin,tester,contributor", "SLACK_FLAGGING_FOOTER_LINK": "https://habitrpg.github.io/flag-o-rama/", "SLACK_FLAGGING_URL": "https://hooks.slack.com/services/id/id/id", "SLACK_SUBSCRIPTIONS_URL": "https://hooks.slack.com/services/id/id/id", diff --git a/website/server/middlewares/index.js b/website/server/middlewares/index.js index 0ca550f7c4..20f7e28a48 100644 --- a/website/server/middlewares/index.js +++ b/website/server/middlewares/index.js @@ -79,7 +79,12 @@ module.exports = function attachMiddlewares (app, server) { // The site can require basic HTTP authentication to be accessed if (ENABLE_HTTP_AUTH) { const httpBasicAuthUsers = {}; - httpBasicAuthUsers[nconf.get('SITE_HTTP_AUTH_USERNAME')] = nconf.get('SITE_HTTP_AUTH_PASSWORD'); + const usernames = nconf.get('SITE_HTTP_AUTH_USERNAMES').split(','); + const passwords = nconf.get('SITE_HTTP_AUTH_PASSWORDS').split(','); + + usernames.forEach((user, index) => { + httpBasicAuthUsers[user] = passwords[index]; + }); app.use(basicAuth({ users: httpBasicAuthUsers,