Skip to content

Commit b51e31f

Browse files
committed
include standard claims from payload. closes auth0#196
1 parent d805573 commit b51e31f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

sign.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ module.exports = function(payload, secretOrPrivateKey, options, callback) {
9393

9494
Object.keys(options_to_payload).forEach(function (key) {
9595
var claim = options_to_payload[key];
96-
if (typeof options[key] !== 'undefined' && typeof payload[claim] !== 'undefined') {
97-
throw new Error('Bad "options.' + key + '" option. The payload already has an "' + claim + '" property.');
96+
if (typeof options[key] !== 'undefined') {
97+
if (typeof payload[claim] !== 'undefined') {
98+
throw new Error('Bad "options.' + key + '" option. The payload already has an "' + claim + '" property.');
99+
}
100+
payload[claim] = options[key];
98101
}
99-
payload[claim] = options[key];
100102
});
101103

102104
var encoding = options.encoding || 'utf8';

test/issue_196.tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var expect = require('chai').expect;
2+
var jwt = require('./..');
3+
var atob = require('atob');
4+
5+
describe('issue 196', function () {
6+
function b64_to_utf8 (str) {
7+
return decodeURIComponent(escape(atob( str )));
8+
}
9+
10+
it('should use issuer provided in payload.iss', function () {
11+
var token = jwt.sign({ iss: 'foo' }, 'shhhhh');
12+
var decoded_issuer = JSON.parse(b64_to_utf8(token.split('.')[1])).iss;
13+
expect(decoded_issuer).to.equal('foo');
14+
});
15+
});

0 commit comments

Comments
 (0)