newsource-token-caching-manager
v1.1.2
Published
Module to manage token caching
Downloads
11
Readme
newsource-token-caching-manager
Installation
~$: npm install --save newsource-token-caching-manager
Usage
To create an instance of the token caching manager you will need to provide a url, a string name for the cache location, a string name of the expiration key, a string name of the token key, and an optional api method type. When called successfully will return an async function that can be used to retrive a token from cache or an api.
const { createTokenManager } = require("newsource-token-caching-manager");
const tokenRetriever = createTokenManager({
url: "url goes here, required",
cacheName: "cache name goes here, required",
expirationParameter: "object key of expiration retrieved from api, required",
tokenParameter: "object key of token retreived from api, required",
methodType: "optional api method type goes here (eg., post, get)"
});
const token = await tokenRetreiver();
// You may also pass in a forceRetrieve flag to tokenRetriever to get a new token from api and write it to cache
const newToken = await tokenRetriever(true);