Skip to content

Commit

Permalink
Add support for server-side basic auth
Browse files Browse the repository at this point in the history
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
mansilladev committed Apr 24, 2013
1 parent 9d99e48 commit 7f3df0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
4 changes: 4 additions & 0 deletions config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"port" : 3000,
"debug" : false,
"sessionSecret" : "12345",
"basicAuth": {
"username":"",
"password":""
},
"redis" : {
"host" : "localhost",
"port" : 6379,
Expand Down

0 comments on commit 7f3df0a

Please sign in to comment.