UNPKG

jwks-rsa

Version:

Library to retrieve RSA public keys from a JWKS endpoint

16 lines (13 loc) 521 B
const logger = require('debug')('jwks'); const memoizer = require('lru-memoizer'); const { promisify, callbackify } = require('util'); function cacheWrapper(client, { cacheMaxEntries = 5, cacheMaxAge = 600000 }) { logger(`Configured caching of signing keys. Max: ${cacheMaxEntries} / Age: ${cacheMaxAge}`); return promisify(memoizer({ hash: (kid) => kid, load: callbackify(client.getSigningKey.bind(client)), maxAge: cacheMaxAge, max: cacheMaxEntries })); } module.exports.default = cacheWrapper;