Skip to content

Instantly share code, notes, and snippets.

@gregfroese
Last active August 29, 2015 14:05
Show Gist options
  • Save gregfroese/837d64ed30566e3978ce to your computer and use it in GitHub Desktop.
Save gregfroese/837d64ed30566e3978ce to your computer and use it in GitHub Desktop.
jwtauth.js
var rpc = require('amqp-rpc').factory({
url: "amqp://guest:guest@localhost:5672"
});
module.exports = function(req, res, next) {
var jwt = require('jwt-simple');
token = (req.body && req.body.access_token) || (req.query && req.query.access_token) || req.headers['x-access-token'];
rpc.call('profile.confirmToken', {token: token}, function(result, user, msg) {
if(result) {
//token is authenticated
req.user = user;
next();
} else {
//token is invalid
next();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment