atlassian-connect-auth
Version:
Helper for handling webhooks from Atlassian products
28 lines (27 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CachingKeyProvider = void 0;
/**
* General-purpose implementation that facilitates caching a recent public key in case CDN is inaccessible.
* Caching is optional and, if used, must be done by the `kid`. Public keys should be rotated often and will get a new
* kid every time which will then effectively invalidate the cache.
*/
class CachingKeyProvider {
constructor(provider, cache) {
this.provider = provider;
this.cache = cache;
}
async get(kid, unverifiedConnectJwt) {
// Obtain cached value, if any
const cachedKey = await this.cache.get(kid);
if (cachedKey) {
return cachedKey;
}
// Obtain new value
const newKey = await this.provider.get(kid, unverifiedConnectJwt);
// Cache new value and return
await this.cache.set(kid, newKey);
return newKey;
}
}
exports.CachingKeyProvider = CachingKeyProvider;