jwt icon indicating copy to clipboard operation
jwt copied to clipboard

Optimize secret matching

Open litoj opened this issue 11 months ago • 0 comments

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);
}

litoj avatar Jan 26 '25 13:01 litoj