From 084f537d3dfbcef2bea411cc0a1515899cc8aa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20F=2E=20Romaniello?= Date: Tue, 12 Jul 2016 10:06:23 -0300 Subject: [PATCH] do not stringify the payload when signing async - closes #224 --- sign.js | 5 ++--- test/async_sign.tests.js | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sign.js b/sign.js index 470d416..5d26ef7 100644 --- a/sign.js +++ b/sign.js @@ -127,10 +127,9 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) { jws.createSign({ header: header, privateKey: secretOrPrivateKey, - payload: JSON.stringify(payload), + payload: payload, encoding: encoding - }) - .once('error', callback) + }).once('error', callback) .once('done', function (signature) { callback(null, signature); }); diff --git a/test/async_sign.tests.js b/test/async_sign.tests.js index d013f5e..e30ac53 100644 --- a/test/async_sign.tests.js +++ b/test/async_sign.tests.js @@ -1,5 +1,6 @@ var jwt = require('../index'); var expect = require('chai').expect; +var jws = require('jws'); describe('signing a token asynchronously', function() { @@ -40,5 +41,13 @@ describe('signing a token asynchronously', function() { done(); }); }); + + it('should not stringify the payload', function (done) { + jwt.sign('string', 'secret', {}, function (err, token) { + if (err) { return done(err); } + expect(jws.decode(token).payload).to.equal('string'); + done(); + }); + }); }); });