@kbabichau/access-integration-client
v1.2.1
Published
Access integration client
Downloads
161
Readme
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 (eitherstaging
orproduction
) 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.