var jwt = require('jsonwebtoken');
module.exports = {
inbound: function(req, res, next) {
self = this;
// first check for a header
if (req.headers['x-jetstream-jwt']) {
// now we need to check the jwt is legit
var token = req.headers['x-jetstream-jwt'];
jwt.verify(token, jetstreamConfig.jwt_secret, { issuer: jetstreamConfig.registry_url, audience: jetstreamConfig.location }, function(err, decoded) {
if (decoded) {
next();
} else {
res.status(401).send("Unauthorized")
console.log("Error: " + err);
console.log("Token: " + token);
console.log("Expected registry: " + jetstreamConfig.registry_url);
console.log("Expected audience: " + jetstreamConfig.location);
}
});
} else {
res.status(401).send("Unauthorized")
console.log("Unauthorized: No header");
}
},
outbound: function() {
return jwt.sign({},
jetstreamConfig.jwt_secret, {
issuer: jetstreamConfig.location, // iss - issuer
audience: jetstreamConfig.registry_url, // aud - audience
expiresIn: 5, // exp - expires after
noTimestamp: false // iat - issued at
});
}
} |