Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Apple's nonce_supported claim #841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/option-nonce-supported.test.js
@@ -0,0 +1,41 @@
'use strict';

const jwt = require('../');
const expect = require('chai').expect;
const testUtils = require('./test-utils')

describe('nonce and nonce_supported option', function () {

[
{
description: 'should succeed without nonce and without nonce support',
signParam: { nonce_supported: false },
verifyParam: { },
},
{
description: 'should succeed without nonce but with nonce support',
signParam: { nonce_supported: true },
verifyParam: { },
},
{
description: 'should succeed with nonce but without nonce support',
signParam: { nonce_supported: false },
verifyParam: { nonce: 'abcde' },
},
{
description: 'should succeed with nonce and nonce support',
signParam: { nonce: 'abcde', nonce_supported: true },
verifyParam: { nonce: 'abcde' },
},
].forEach((testCase) => {
it(testCase.description, function (done) {
var token = jwt.sign(testCase.signParam, undefined, { algorithm: 'none' });
testUtils.verifyJWTHelper(token, undefined, testCase.verifyParam, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.null;
});
});
});
});

});
2 changes: 1 addition & 1 deletion verify.js
Expand Up @@ -191,7 +191,7 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) {
}

if (options.nonce) {
if (payload.nonce !== options.nonce) {
if (payload.nonce !== options.nonce && payload.nonce_supported !== false) {
return done(new JsonWebTokenError('jwt nonce invalid. expected: ' + options.nonce));
}
}
Expand Down