diff --git a/index.js b/index.js index cbb0acb..c19c73f 100644 --- a/index.js +++ b/index.js @@ -431,9 +431,9 @@ var jwtLib = { jwt.setSigningAlgorithm(args.length===3 ? alg : 'HS256'); jwt.setSigningKey(secret); } - jwt.setExpiration((nowEpochSeconds() + (60*60))*1000); // one hour + jwt.setExpiration(claims.exp * 1000 || (nowEpochSeconds() + (60 * 60)) * 1000); return jwt; } }; -module.exports = jwtLib; \ No newline at end of file +module.exports = jwtLib; diff --git a/test/builder.js b/test/builder.js index c1a20d2..c712d5a 100644 --- a/test/builder.js +++ b/test/builder.js @@ -66,6 +66,12 @@ describe('create()',function(){ assert.equal(nJwt.create({},uuid()).body.exp , oneHourFromNow); }); + it('should not create default exp field, if exp is given',function(){ + var time = Math.floor(Date.now()/1000) + var token = nJwt.create({exp: time},uuid()) + assert.equal(token.body.exp , time); + }); + it('should not overwrite a defined jti field',function(){ assert.equal(nJwt.create({jti: 1},uuid()).body.jti , 1); }); @@ -108,6 +114,3 @@ describe('base64 URL Encoding',function(){ }); }); - - -