mirror of
https://github.com/hanzoai/node-jsonwebtoken.git
synced 2026-09-24 17:00:48 +00:00
Merge branch 'popomore-standard-callback'
This commit is contained in:
@@ -132,7 +132,11 @@ JWT.sign = function(payload, secretOrPrivateKey, options, callback) {
|
||||
header: header,
|
||||
privateKey: secretOrPrivateKey,
|
||||
payload: JSON.stringify(payload)
|
||||
}).on('done', callback);
|
||||
})
|
||||
.on('error', callback)
|
||||
.on('done', function(signature) {
|
||||
callback(null, signature);
|
||||
});
|
||||
} else {
|
||||
return jws.sign({header: header, payload: payload, secret: secretOrPrivateKey, encoding: encoding});
|
||||
}
|
||||
|
||||
@@ -9,12 +9,19 @@ describe('signing a token asynchronously', function() {
|
||||
var syncToken = jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS256' });
|
||||
|
||||
it('should return the same result as singing synchronously', function(done) {
|
||||
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS256' }, function (asyncToken) {
|
||||
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS256' }, function (err, asyncToken) {
|
||||
expect(asyncToken).to.be.a('string');
|
||||
expect(asyncToken.split('.')).to.have.length(3);
|
||||
expect(asyncToken).to.equal(syncToken);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error', function(done) {
|
||||
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'HS2561' }, function (err) {
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user