Skip to content

Commit

Permalink
Added extra url end-points for checking authentication and authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Oct 15, 2012
1 parent 35f271c commit 2f951a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var security = {
},
sendCurrentUser: function(req, res, next) {
res.json(200, filterUser(req.user));
res.end();
},
login: function(req, res, next) {
function authenticationFailed(err, user, info){
Expand Down
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ app.post('/logout', security.logout);
// Retrieve the current user
app.get('/current-user', security.sendCurrentUser);

// Retrieve the current user only if they are authenticated
app.get('/authenticated-user', function(req, res) {
security.authenticationRequired(req, res, function() { security.sendCurrentUser(req, res); });
});

// Retrieve the current user only if they are admin
app.get('/admin-user', function(req, res) {
security.adminRequired(req, res, function() { security.sendCurrentUser(req, res); });
});

// This route deals enables HTML5Mode by forwarding missing files to the index.html
app.all('/*', function(req, res) {
// Just send the index.html for other files to support HTML5Mode
Expand Down

0 comments on commit 2f951a7

Please sign in to comment.