@ist-group/client-credentials-access-token-provider
TypeScript icon, indicating that this package has built-in type declarations

6.0.3 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @ist-group/client-credentials-access-token-provider

Weekly Downloads

7

Version

6.0.3

License

none

Unpacked Size

20.7 kB

Total Files

12

Last publish

Collaborators

  • omer.irfan
  • rhine
  • gabts