From c81740e3391376065ea946d9b6371fc020bbe38f Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Thu, 3 Apr 2014 16:04:11 -0700 Subject: [PATCH] Add basic auth support to API --- lib/api.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/api.js b/lib/api.js index 54bc14e..6b6c4fb 100644 --- a/lib/api.js +++ b/lib/api.js @@ -40,6 +40,16 @@ namespace("Cylon", function() { this.server.set('title', 'Cylon API Server'); + // configure basic auth, if requested + if (opts.auth.type && opts.auth.type === 'basic') { + var user = opts.auth.user, + pass = opts.auth.pass; + + if (user && pass) { + this.server.use(express.basicAuth(user, pass)); + } + } + this.server.use(express.json()); this.server.use(express.urlencoded()); this.server.use(express["static"](__dirname + "/../node_modules/robeaux/"));