From 322fe50afeea9e4d5a7775c8d119aaf6c76703c6 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 20 Apr 2017 15:43:55 +0200 Subject: [PATCH] #39 add support for auth, update documentation, bump version --- README.md | 4 ++++ lib/setupAndMiddleware.js | 16 ++++++++++++++-- package.json | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c94457c..41260ca 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ var matador = require('bull-ui/app')({ host: your host name, port: your port number, password: optional auth password + }, + auth: { // optional + username: 'admin', + password: 'password' } }); ``` diff --git a/lib/setupAndMiddleware.js b/lib/setupAndMiddleware.js index bf376c9..2836186 100644 --- a/lib/setupAndMiddleware.js +++ b/lib/setupAndMiddleware.js @@ -1,6 +1,7 @@ var redisAdapter = require('./redisConnector'), - express = require('express'); -var bodyParser = require('body-parser'); + express = require('express'), + bodyParser = require('body-parser'), + auth = require('http-auth'); module.exports = function(app, options){ options = options || {}; @@ -20,6 +21,17 @@ module.exports = function(app, options){ //Enforce that redis is connected to, will make render an error page if not connected app.use(redisConnectionEnforcer); + // Add authentication if specified + if(options.auth){ + var basic = auth.basic({ + realm: 'NOTHING TO SEE HERE' + }, function(username, password, callback) { + callback(username == options.auth.username && password == options.auth.password); + }) + + app.use(auth.connect(basic)) + } + app.use(bodyParser.urlencoded({extended: true})); //Publicly accessible routes diff --git a/package.json b/package.json index e99a48c..da68809 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bull-ui", - "version": "1.2.3", + "version": "1.2.4", "description": "Front-end web interface for Bull Job Manager", "main": "index.js", "dependencies": { @@ -10,6 +10,7 @@ "consolidate": "~0.10.0", "dustjs-linkedin": "~2.5.1", "express": "^4.13.4", + "http-auth": "^3.1.3", "less": "~2.1.2", "lodash": "~2.4.1", "moment": "^2.17.1",