Skip to content

Commit

Permalink
Merge pull request #277 from skyzyx/master
Browse files Browse the repository at this point in the history
Implemented keyid (kid) attribute in JWT header (Part II)
  • Loading branch information
jfromaniello committed Dec 6, 2016
2 parents aecb4d1 + b412be9 commit 2c54016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var sign_options_schema = Joi.object().keys({
issuer: Joi.string(),
subject: Joi.string(),
jwtid: Joi.string(),
noTimestamp: Joi.boolean()
noTimestamp: Joi.boolean(),
keyid: Joi.string()
});

var registered_claims_schema = Joi.object().keys({
Expand Down Expand Up @@ -49,7 +50,8 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {

var header = xtend({
alg: options.algorithm || 'HS256',
typ: isObjectPayload ? 'JWT' : undefined
typ: isObjectPayload ? 'JWT' : undefined,
kid: options.keyid
}, options.header);

function failure(err) {
Expand Down
9 changes: 9 additions & 0 deletions test/keyid.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var jwt = require('../index');

var claims = {"name": "doron", "age": 46};
jwt.sign(claims, 'secret', {"keyid": "1234"}, function(err, good) {
console.log(jwt.decode(good, {"complete": true}).header.kid);
jwt.verify(good, 'secret', function(err, result) {
console.log(result);
})
});

0 comments on commit 2c54016

Please sign in to comment.