authelia/app/lib/jwt.js

30 lines
536 B
JavaScript
Raw Normal View History

2016-12-10 07:47:58 +07:00
module.exports = Jwt;
var jwt = require('jsonwebtoken');
var utils = require('./utils');
var Q = require('q');
function Jwt(secret) {
var _secret;
this._secret = secret;
}
Jwt.prototype.sign = function(data, expiration_time) {
return jwt.sign(data, this._secret, { expiresIn: expiration_time });
}
Jwt.prototype.verify = function(token) {
var defer = Q.defer();
try {
var decoded = jwt.verify(token, this._secret);
defer.resolve(decoded);
}
catch(err) {
defer.reject(err);
}
return defer.promise;
}