Skip to content

Commit

Permalink
do not stringify the payload when signing async - closes #224
Browse files Browse the repository at this point in the history
  • Loading branch information
jfromaniello committed Jul 12, 2016
1 parent 7a180a6 commit 084f537
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
9 changes: 9 additions & 0 deletions test/async_sign.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var jwt = require('../index');
var expect = require('chai').expect;
var jws = require('jws');

describe('signing a token asynchronously', function() {

Expand Down Expand Up @@ -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();
});
});
});
});

0 comments on commit 084f537

Please sign in to comment.