@kbabichau/access-integration-client
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

AccessClient

The AccessClient class is designed to simplify authentication and token management for HTTP requests.

Installation

npm install @kbabichau/access-integration-client

Usage

To use AccessClient, start by importing it at the top of your script:

import AccessClient, { AccessEnvironment } from '@kbabichau/access-integration-client';

Then, instantiate the AccessClient class, passing in your configuration object:

const client = new AccessClient({
  environment: AccessEnvironment.Staging,
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});

You can then use various methods such as getToken() to retrieve an access token, and getExchangedToken(aud) to retrieve an access token that has been exchanged for a specified audience.

const accessToken = await client.getToken(); // Retrieves an access token
const exchangedToken = await client.getExchangedToken('external-system-client-id'); // Retrieves an access token exchanged for a specified audience

Example of typical usage for integration with external system:

const client = new AccessClient({
  environment: AccessEnvironment.Staging,
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});

const token = await client.getExchangedToken('external-system-client-id');

const response = await axios.get('external-system.com/api/articles', {
  headers: {
    Authorization: `Bearer ${token}`
  }
});

API

new AccessClient(config)

Returns a new instance of the AccessClient class.

Arguments:

  • config (object):
    • environment (string, required) - The environment (either staging or production) of your server for authentication.
    • clientId (string, required) - The client ID for your application.
    • clientSecret (string, required) - The client secret for your application.

client.getToken()

Returns a promise that resolves to the access token for your application.

client.getExchangedToken(aud)

Returns a promise that resolves to the access token that has been exchanged for a specified audience.

Arguments:

  • aud (string, required) - The audience to which the token is being exchanged.

client.ping()

Returns a promise that resolves to ping the server and confirm endpoint is available.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @kbabichau/access-integration-client

Weekly Downloads

33

Version

1.2.1

License

ISC

Unpacked Size

38.1 kB

Total Files

23

Last publish

Collaborators

  • kbabichau