Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: auth0/node-jsonwebtoken
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.5.2
Choose a base ref
...
head repository: auth0/node-jsonwebtoken
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.5.3
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 4, 2016

  1. minor

    jfromaniello committed Jan 4, 2016
    Copy the full SHA
    65b1f58 View commit details
  2. 6
    Copy the full SHA
    71200f1 View commit details
  3. 5.5.3

    jfromaniello committed Jan 4, 2016
    Copy the full SHA
    04a76d5 View commit details
Showing with 28 additions and 3 deletions.
  1. +19 −1 index.js
  2. +1 −1 package.json
  3. +1 −1 test/{bug_147.tests.js → issue_147.tests.js}
  4. +7 −0 test/non_object_values.tests.js
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -38,15 +38,33 @@ JWT.decode = function (jwt, options) {
return payload;
};

var payload_options = [
'expiresIn',
'notBefore',
'expiresInMinutes',
'expiresInSeconds',
'audience',
'issuer',
'subject',
'jwtid'
];

JWT.sign = function(payload, secretOrPrivateKey, options, callback) {
options = options || {};
payload = typeof payload === 'object' ? xtend(payload) : payload;
var header = {};

if (typeof payload === 'object') {
header.typ = 'JWT';
payload = xtend(payload);
} else {
var invalid_option = payload_options.filter(function (key) {
return typeof options[key] !== 'undefined';
})[0];

console.warn('invalid "' + invalid_option + '" option for ' + (typeof payload) + ' payload');
}


header.alg = options.algorithm || 'HS256';

if (options.headers) {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonwebtoken",
"version": "5.5.2",
"version": "5.5.3",
"description": "JSON Web Token implementation (symmetric and asymmetric)",
"main": "index.js",
"scripts": {
2 changes: 1 addition & 1 deletion test/bug_147.tests.js → test/issue_147.tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var jwt = require('../index');
var expect = require('chai').expect;

describe('signing with a sealed payload', function() {
describe('issue 147 - signing with a sealed payload', function() {

it('should put the expiration claim', function () {
var token = jwt.sign(Object.seal({foo: 123}), '123', { expiresIn: 10 });
7 changes: 7 additions & 0 deletions test/non_object_values.tests.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,13 @@ describe('non_object_values values', function() {
expect(result).to.equal('hello');
});

//v6 version will throw in this case:
it.skip('should throw with expiresIn', function () {
expect(function () {
jwt.sign('hello', '123', { expiresIn: '12h' });
}).to.throw(/invalid expiresIn option for string payload/);
});

it('should fail to validate audience when the payload is string', function () {
var token = jwt.sign('hello', '123');
expect(function () {