-
Notifications
You must be signed in to change notification settings - Fork 126
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
Support custom verification function or disable verification #120
Comments
Hi @stongo,
Which means you "just" have to create your own Please let us know if you need help with implementing a |
Thanks for the quick response @nelsonic |
@stongo right, in the scenario you are describing you can simply have a list (array or object) of keys and iterate through them until you are sure the verification failed. var keys = [ 'key1', 'key2', 'key3', 'etc' ];
var key;
var i = keys.length;
while(i > 0) {
if( jwt.verify(token, keys[i]) ) {
key = keys[i];
break; // we found the key we need
}
else { // keep iterating
i--;
}
}
return key || false; This code is not elegant, but I think it will do what you need. |
Right, but the drawback being the token gets verified twice (an extra time in key function |
Agreed. Its suboptimal... var keys = {
"k1":"yourkeyhere",
"k2":"anotherkeyhere",
"k3": "etc.etc..."
} then store the name of the key inside the JWT: var token = JWT.sign({"keyname":"k1", "other":"other claims" }, keys['k2'] ); and instead of verifying the JWT inside the var decoded = JWT.decode(token); // decoding does not require us to know the key's name
return decoded.keyname; // the key to be used to verify THIS token. Then in your var key = keyFunc();
var verified = JWT.verify(token, key); You could dynamically lookup the keyname in any DB if you prefer not use an Object in your app. |
Marking as closed. Realized the validate function doesn't pass the token anyway so following your advice. Thanks for your help! |
@stongo are you sure? if the you need a more specific solution to your quest we are happy to help further... 👍 |
Re-opening this because I realize both the In the case of Dex, the token is immutable because it only provides the public key which cannot be used for resigning a modified token. So it seems then it might be handy to provide the raw token in the |
@stongo do you have an idea of the desired format for a |
@stongo the latest release var customVerifyFunc = function (decoded, request, callback) {
return callback(null, true, decoded);
}; Let me us know if you need anything else. 👍 (Closing this issue as I think its resolved, but feel free to re-open if not...) |
I'm in the process of implementing Dex
The reason for this request is because Dex uses and rotates through multiple keys to sign JWT tokens. Added to the complexity is the fact one has to generate the keys to verify tokens from an array of modulus/exponent pairs.
This leaves this module's current paradigm of providing one key to pass to jwt.verify() a blocker.
I wondered about the following solutions
I would be more than glad to provide a PR if you would agree on a way to tackle this in this module
The text was updated successfully, but these errors were encountered: