1.2.1 • Published 2 months ago

@kbabichau/access-integration-client v1.2.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

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

1.2.1

2 months ago

1.2.0

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago