Socket
Socket
Sign inDemoInstall

jsonwebtoken

Package Overview
Dependencies
6
Maintainers
6
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.3.1 to 5.4.0

test/expires_format.tests.js

31

index.js
var jws = require('jws');
var ms = require('ms');

@@ -60,8 +61,30 @@ var JWT = module.exports;

var expiresInSeconds = options.expiresInMinutes ?
options.expiresInMinutes * 60 :
options.expiresInSeconds;
if (options.expiresInSeconds || options.expiresInMinutes) {
var deprecated_line;
try {
deprecated_line = /.*\((.*)\).*/.exec((new Error()).stack.split('\n')[2])[1];
} catch(err) {
deprecated_line = '';
}
if (expiresInSeconds) {
console.warn('jsonwebtoken: expiresInMinutes and expiresInSeconds is deprecated. (' + deprecated_line + ')\n' +
'Use "expiresIn" expressed in seconds.');
var expiresInSeconds = options.expiresInMinutes ?
options.expiresInMinutes * 60 :
options.expiresInSeconds;
payload.exp = timestamp + expiresInSeconds;
} else if (options.expiresIn) {
if (typeof options.expiresIn === 'string') {
var milliseconds = ms(options.expiresIn);
if (typeof milliseconds === 'undefined') {
throw new Error('bad "expiresIn" format: ' + options.expiresIn);
}
payload.exp = timestamp + milliseconds / 1000;
} else if (typeof options.expiresIn === 'number' ) {
payload.exp = timestamp + options.expiresIn;
} else {
throw new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60');
}
}

@@ -68,0 +91,0 @@

2

package.json
{
"name": "jsonwebtoken",
"version": "5.3.1",
"version": "5.4.0",
"description": "JSON Web Token implementation (symmetric and asymmetric)",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -28,3 +28,3 @@ # jsonwebtoken [![Build Status](https://secure.travis-ci.org/auth0/node-jsonwebtoken.png)](http://travis-ci.org/auth0/node-jsonwebtoken)

* `algorithm` (default: `HS256`)
* `expiresInMinutes` or `expiresInSeconds`
* `expiresIn`: expressed in seconds or an string describing a time span [rauchg/ms](https://github.com/rauchg/ms.js). Eg: `60`, `"2 days"`, `"10h"`, `"7d"`
* `audience`

@@ -39,3 +39,3 @@ * `subject`

If any `expiresInMinutes`, `audience`, `subject`, `issuer` are not provided, there is no default. The jwt generated won't include those properties in the payload.
If any `expiresIn`, `audience`, `subject`, `issuer` are not provided, there is no default. The jwt generated won't include those properties in the payload.

@@ -42,0 +42,0 @@ Additional headers can be provided via the `headers` object.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc