Skip to content

Commit 6a7b98f

Browse files
committed
Add support for Apple's nonce_supported claim
Apple's authentication identity token can contain a non-standard nonce_supported claim. As specified, when this is set to false skip the nonce check. https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple
1 parent 74d5719 commit 6a7b98f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

test/option-nonce-supported.test.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const jwt = require('../');
4+
const expect = require('chai').expect;
5+
const testUtils = require('./test-utils')
6+
7+
describe('nonce and nonce_supported option', function () {
8+
9+
[
10+
{
11+
description: 'should succeed without nonce and without nonce support',
12+
signParam: { nonce_supported: false },
13+
verifyParam: { },
14+
},
15+
{
16+
description: 'should succeed without nonce but with nonce support',
17+
signParam: { nonce_supported: true },
18+
verifyParam: { },
19+
},
20+
{
21+
description: 'should succeed with nonce but without nonce support',
22+
signParam: { nonce_supported: false },
23+
verifyParam: { nonce: 'abcde' },
24+
},
25+
{
26+
description: 'should succeed with nonce and nonce support',
27+
signParam: { nonce: 'abcde', nonce_supported: true },
28+
verifyParam: { nonce: 'abcde' },
29+
},
30+
].forEach((testCase) => {
31+
it(testCase.description, function (done) {
32+
var token = jwt.sign(testCase.signParam, undefined, { algorithm: 'none' });
33+
testUtils.verifyJWTHelper(token, undefined, testCase.verifyParam, (err) => {
34+
testUtils.asyncCheck(done, () => {
35+
expect(err).to.be.null;
36+
});
37+
});
38+
});
39+
});
40+
41+
});

verify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) {
191191
}
192192

193193
if (options.nonce) {
194-
if (payload.nonce !== options.nonce) {
194+
if (payload.nonce !== options.nonce && payload.nonce_supported !== false) {
195195
return done(new JsonWebTokenError('jwt nonce invalid. expected: ' + options.nonce));
196196
}
197197
}

0 commit comments

Comments
 (0)