Skip to content

Commit 084f537

Browse files
committed
do not stringify the payload when signing async - closes #224
1 parent 7a180a6 commit 084f537

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: sign.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {
127127
jws.createSign({
128128
header: header,
129129
privateKey: secretOrPrivateKey,
130-
payload: JSON.stringify(payload),
130+
payload: payload,
131131
encoding: encoding
132-
})
133-
.once('error', callback)
132+
}).once('error', callback)
134133
.once('done', function (signature) {
135134
callback(null, signature);
136135
});

Diff for: test/async_sign.tests.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var jwt = require('../index');
22
var expect = require('chai').expect;
3+
var jws = require('jws');
34

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

@@ -40,5 +41,13 @@ describe('signing a token asynchronously', function() {
4041
done();
4142
});
4243
});
44+
45+
it('should not stringify the payload', function (done) {
46+
jwt.sign('string', 'secret', {}, function (err, token) {
47+
if (err) { return done(err); }
48+
expect(jws.decode(token).payload).to.equal('string');
49+
done();
50+
});
51+
});
4352
});
4453
});

0 commit comments

Comments
 (0)