Skip to content

Instantly share code, notes, and snippets.

@Jigarsolanki
Created December 8, 2012 20:42
Show Gist options
  • Save Jigarsolanki/4241841 to your computer and use it in GitHub Desktop.
Save Jigarsolanki/4241841 to your computer and use it in GitHub Desktop.
user/auth handler
exports.generateToken = function(req, res) {
var username, password;
username = req.param('username');
password = req.param('password');
if(username === 'foo' && password === 'bar') {
res.send(200, {'token': "ABC123"});
} else {
res.send(401, {'message': 'Unauthorised'});
}
};
exports.authorize = function(req, res, next) {
var token;
token = req.headers['auth-token'] || '';
if(token !== "ABC123") {
res.send(401, {'message': 'Unauthorised'});
} else {
next();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment