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

Update to jws@^3.0.0 #78

Merged
merged 3 commits into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 15 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,27 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
~secretOrPublicKey.toString().indexOf('BEGIN PUBLIC KEY') ?
[ 'RS256','RS384','RS512','ES256','ES384','ES512' ] :
~secretOrPublicKey.toString().indexOf('BEGIN RSA PUBLIC KEY') ?
[ 'RS256','RS384','RS512' ] :
[ 'HS256','HS384','HS512' ];
[ 'RS256','RS384','RS512' ] :
[ 'HS256','HS384','HS512' ];

}

var decodedToken = jws.decode(jwtString);

if (!decodedToken) {
return done(new JsonWebTokenError('invalid token'));
}

var header = decodedToken.header;

if (!~options.algorithms.indexOf(header.alg)) {
return done(new JsonWebTokenError('invalid signature'));
Copy link
Member

Choose a reason for hiding this comment

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

@jfromaniello @pose should this be 'invalid header' or 'invalid "alg" claim'?

}

var valid;

try {
valid = jws.verify(jwtString, secretOrPublicKey);
valid = jws.verify(jwtString, header.alg, secretOrPublicKey);
} catch (e) {
return done(e);
}
Expand All @@ -136,11 +148,6 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
return done(err);
}

var header = jws.decode(jwtString).header;
if (!~options.algorithms.indexOf(header.alg)) {
return done(new JsonWebTokenError('invalid signature'));
}

if (typeof payload.exp !== 'undefined' && !options.ignoreExpiration) {
if (typeof payload.exp !== 'number') {
return done(new JsonWebTokenError('invalid exp value'));
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"url": "https://github.com/auth0/node-jsonwebtoken/issues"
},
"dependencies": {
"jws": "~2.0.0"
"jws": "^3.0.0"
},
"devDependencies": {
"atob": "~1.1.2",
"chai": "~1.10.0",
"mocha": "~2.1.0"
"atob": "^1.1.2",
"chai": "^1.10.0",
"mocha": "^2.1.0"
},
"engines": {
"npm": ">=1.4.28"
Expand Down
2 changes: 1 addition & 1 deletion test/jwt.rs.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('RS256', function() {
jwt.verify('fruit.fruit.fruit', pub, function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
assert.equal(err.name, 'Error');
assert.equal(err.name, 'JsonWebTokenError');
done();
});
});
Expand Down