Files
node-jsonwebtoken/test/verify.tests.js
T
Andrew Balmos 5290db1bd7 First assume JWT claim set is an object
draft-ietf-oauth-json-web-token does not require JWT objects to have typ: "JWT"
in their header. Yet it expects that the JWT's claim set be JSON for validation.
See step 10 of draft-ietf-oauth-json-web-token section 7.2 "Validating a JWT".

Prior to this commit JWTs without typ: "JWT" in header are validated without
ever checking the claim set.
2015-03-06 16:33:05 -05:00

29 lines
738 B
JavaScript

var jwt = require('../index');
var jws = require('jws');
var fs = require('fs');
var path = require('path');
var assert = require('chai').assert;
describe('verify', function() {
var pub = fs.readFileSync(path.join(__dirname, 'pub.pem'));
var priv = fs.readFileSync(path.join(__dirname, 'priv.pem'));
it('should first assume JSON claim set', function () {
var header = { alg: 'RS256' };
var payload = { iat: Math.floor(Date.now() / 1000 ) };
var signed = jws.sign({
header: header,
payload: payload,
secret: priv,
encoding: 'utf8'
});
jwt.verify(signed, pub, {typ: 'JWT'}, function(err, p) {
assert.isNull(err);
assert.deepEqual(p, payload);
});
});
});