Skip to main content

Async

AsyncSecretKeyStorage is installed by default and it is not suppose to be used directly but rather be extended or instantiated with a specific loader implementation.

It resolves secret and retains it in cache for a period of time. Once secret expires it is reloaded from the loader upon another attempt of usage.

All async loaders (for example AWS DynamoDB) are using it to reduce the number of requests to the storage, improve performance of token verification.

Example usage

import {AsyncSecretKeyStorage} from '@farbor/secret-storage';
import {Duration} from 'luxon';

const secretStorage = new AsyncSecretKeyStorage((keyId) => {
return loadKeyFromSomewhere(keyId); // returns Promise<Buffer>
}, {
cacheTtl: Duration.from({hours: 5}) // store secret for 5 hours once retrieved
});