Skip to content
Browse files

Add support for server-side basic auth

This enables basic auth on the Node server -- so that in order to
access I/O Docs (http://localhost:3000, for example), you will need to
enter in a username and password.  This should not be confused with
adding basic auth support while making API calls within the I/O Docs
configured API.
  • Loading branch information...
1 parent 9d99e48 commit 7f3df0a1c86af82f069231ab29a184ad8cef9d12 @mansilladev mansilladev committed Apr 24, 2013
Showing with 22 additions and 0 deletions.
  1. +10 −0 README.md
  2. +8 −0 app.js
  3. +4 −0 config.json.sample
View
10 README.md
@@ -56,6 +56,16 @@ RUNNING I/O DOCS
2. node ./app.js
3. Point your browser to: [http://localhost:3000](http://localhost:3000)
+
+BASIC AUTH FOR SERVER
+---------------------
+Enabling HTTP basic authentication on the server is simple. By default, the username and password values are empty ("").
+
+1. Open up *config.json*
+2. Navigate down to the *basicAuth* object
+3. Add values for username and password within the object
+
+
QUICK API CONFIGURATION EXAMPLE
-------------------------------
Adding an API to the I/O Docs configuration is relatively simple.
View
8 app.js
@@ -105,6 +105,14 @@ app.configure(function() {
})
}));
+ // Global basic authentication on server (applied if configured)
+ if (config.basicAuth && config.basicAuth.username && config.basicAuth.password) {
+ app.use(express.basicAuth(function(user, pass, callback) {
+ var result = (user === config.basicAuth.username && pass === config.basicAuth.password);
+ callback(null /* error */, result);
+ }));
+ }
+
app.use(app.router);
app.use(express.static(__dirname + '/public'));
View
4 config.json.sample
@@ -4,6 +4,10 @@
"port" : 3000,
"debug" : false,
"sessionSecret" : "12345",
+ "basicAuth": {
+ "username":"",
+ "password":""
+ },
"redis" : {
"host" : "localhost",
"port" : 6379,

0 comments on commit 7f3df0a

Please sign in to comment.
Something went wrong with that request. Please try again.