mirror of
https://github.com/hanzoai/node-jsonwebtoken.git
synced 2026-09-24 17:00:48 +00:00
allow passing encoding
This commit is contained in:
@@ -43,7 +43,12 @@ module.exports.sign = function(payload, secretOrPrivateKey, options) {
|
||||
if (options.subject)
|
||||
payload.sub = options.subject;
|
||||
|
||||
var signed = jws.sign({header: header, payload: payload, secret: secretOrPrivateKey});
|
||||
var encoding = 'utf8';
|
||||
if (options.encoding) {
|
||||
encoding = options.encoding;
|
||||
}
|
||||
|
||||
var signed = jws.sign({header: header, payload: payload, secret: secretOrPrivateKey, encoding: encoding});
|
||||
|
||||
return signed;
|
||||
};
|
||||
|
||||
@@ -8,13 +8,20 @@ describe('encoding', function() {
|
||||
return decodeURIComponent(escape(atob( str )));
|
||||
}
|
||||
|
||||
it('should properly encode the token', function () {
|
||||
it('should properly encode the token (utf8)', function () {
|
||||
var expected = 'José';
|
||||
var token = jwt.sign({ name: expected }, 'shhhhh');
|
||||
var decoded_name = JSON.parse(b64_to_utf8(token.split('.')[1])).name;
|
||||
expect(decoded_name).to.equal(expected);
|
||||
});
|
||||
|
||||
it('should properly encode the token (binary)', function () {
|
||||
var expected = 'José';
|
||||
var token = jwt.sign({ name: expected }, 'shhhhh', { encoding: 'binary' });
|
||||
var decoded_name = JSON.parse(atob(token.split('.')[1])).name;
|
||||
expect(decoded_name).to.equal(expected);
|
||||
});
|
||||
|
||||
it('should return the same result when decoding', function () {
|
||||
var username = '測試';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user