jwt
jwt copied to clipboard
Optimize secret matching
I am getting Microsoft Entra ID setup and in this article I clearly saw the possibility to quickly determine the key (secret) to check against by making a map of KeyIDs mapped to key secrets. This would allow decoding with just the correct key, instead of trying them all.
That would change the Array verification to something like this:
let decodedTokens = []
if (secret instanceof Array) {
decodedTokens = secret.map(async s => await verify(token, s, opts));
} else if (secret) {
decodedTokens = verify(token, secret[token.kid] || secret, opts);
}