mirror of
https://github.com/hanzoai/node-jsonwebtoken.git
synced 2026-09-24 17:00:48 +00:00
Merge pull request #5 from dbarbera/master
removes moment dependency using built-in Date.now()
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
var jws = require('jws');
|
||||
var moment = require('moment');
|
||||
|
||||
module.exports.decode = function (jwt) {
|
||||
return jws.decode(jwt).payload;
|
||||
@@ -9,8 +8,13 @@ module.exports.sign = function(payload, secretOrPrivateKey, options) {
|
||||
options = options || {};
|
||||
|
||||
var header = {typ: 'JWT', alg: options.algorithm || 'HS256'};
|
||||
if (options.expiresInMinutes)
|
||||
payload.exp = moment().add('minutes', options.expiresInMinutes).utc().unix();
|
||||
|
||||
payload.iat = Date.now();
|
||||
|
||||
if (options.expiresInMinutes) {
|
||||
var ms = options.expiresInMinutes * 60 * 1000;
|
||||
payload.exp = payload.iat + ms;
|
||||
}
|
||||
|
||||
if (options.audience)
|
||||
payload.aud = options.audience;
|
||||
@@ -21,8 +25,6 @@ module.exports.sign = function(payload, secretOrPrivateKey, options) {
|
||||
if (options.subject)
|
||||
payload.sub = options.subject;
|
||||
|
||||
payload.iat = moment().utc().unix();
|
||||
|
||||
var signed = jws.sign({header: header, payload: payload, secret: secretOrPrivateKey});
|
||||
|
||||
return signed;
|
||||
@@ -46,7 +48,7 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
|
||||
var payload = this.decode(jwtString);
|
||||
|
||||
if (payload.exp) {
|
||||
if (moment().utc().unix() >= payload.exp)
|
||||
if (Date.now() >= payload.exp)
|
||||
return callback(new Error('jwt expired'));
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -19,8 +19,7 @@
|
||||
"url": "https://github.com/auth0/node-jsonwebtoken/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"jws": "~0.2.2",
|
||||
"moment": "~2.0.0"
|
||||
"jws": "~0.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "*",
|
||||
|
||||
Reference in New Issue
Block a user