open-index/open-npm huggingface dataset:
npm package: @ist-group/client-credentials-access-token-provider
Description: 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.
Author: Henrik Cooke
Latest version: 6.0.3

# 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

```bash
yarn add @ist-group/client-credentials-access-token-provider
```

## Usage

```javascript
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.