@ist-group/client-credentials-access-token-provider
v6.0.3
Published
The purpose of this module is to provide a rebost and failure tolerant way to _fetch access tokens_ with the _client credentials_ _OAuth2_ flow _WITHOUT SPAMMING_ the token server.
Downloads
115
Readme
Client Credentials - Access Token Provider
The purpose of this module is to provide a rebost and failure tolerant way to fetch access tokens with the client credentials OAuth2 flow WITHOUT SPAMMING the token server.
Install
yarn add @ist-group/client-credentials-access-token-provider
Usage
import { AccessTokenProvider } from "@ist-group/client-credentials-access-token-provider";
const tokenProvider = new AccessTokenProvider({
tokenEndpoint: 'https://example.com/token',
clientId: 'client-id',
clientSecret: 'client-secret',
scopes: ["scope1", "foo"], // Optional, limit the token to the following scopes
disableAutomaticUpdate: true, // Optional, default: false
onUpdateError: (err) => { // Optional, output is logged to std-out if not defined
console.log("Error fetching token", err.message);
}
});
tokenProvider.getToken().then(accessToken => { .... });
Remarks
The instances of the AccessTokenProvider is intended to be reused and shared across your application.
The options includes a scopes property that is recommended to use when fetching tokens that will be used aginst "untrusted" API:s.