Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ As mentioned in [this comment](https://github.com/auth0/node-jsonwebtoken/issues
* `algorithms`: List of strings with the names of the allowed algorithms. For instance, `["HS256", "HS384"]`.
* `audience`: if you want to check audience (`aud`), provide a value here. The audience can be checked against a string, a regular expression or a list of strings and/or regular expressions.
> Eg: `"urn:foo"`, `/urn:f[o]{2}/`, `[/urn:f[o]{2}/, "urn:bar"]`
* `complete`: return an object with the decoded payload and header
Comment thread
javespi marked this conversation as resolved.
Outdated
* `issuer` (optional): string or array of strings of valid values for the `iss` field.
* `ignoreExpiration`: if `true` do not validate the expiration of the token.
* `ignoreNotBefore`...
Expand Down
24 changes: 24 additions & 0 deletions test/verify.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ describe('verify', function() {
});
});

describe('option: complete', function() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't realize about this before, can you follow similar approach as this option?
https://github.com/auth0/node-jsonwebtoken/blob/master/test/option-nonce.test.js

That is: option-complete.test.js, using testUtils.asyncCheck (to report errors correctly) and testUtils.verifyJWTHelper (to verify sync and async).

We are refactoring the tests moving towards that model so each option and claim has its own tests using common tooling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved here 4d8f50a

Apart from that, I added another unit test for complete: false option.

it('should return header, payload and signature', function (done) {
var header = { alg: 'RS256' };
var payload = { iat: Math.floor(Date.now() / 1000 ) };

var signed = jws.sign({
header: header,
payload: payload,
secret: priv,
encoding: 'utf8'
});

var signature = jws.decode(signed).signature;

jwt.verify(signed, pub, {typ: 'JWT', complete: true}, function(err, p) {
assert.isNull(err);
assert.deepEqual(p.header, header);
assert.deepEqual(p.payload, payload);
assert.deepEqual(p.signature, signature);
done();
});
});
});

describe('secret or token as callback', function () {
var token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU5Mn0.3aR3vocmgRpG05rsI9MpR6z2T_BGtMQaPq2YR6QaroU';
var key = 'key';
Expand Down
10 changes: 10 additions & 0 deletions verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) {
}
}

if (options.complete === true) {
var signature = decodedToken.signature;

return done(null, {
header: header,
payload: payload,
signature: signature
});
}

return done(null, payload);
});
};