genesys-authorization-client-js
v1.0.260
Published
Interface to OAuth Authorization API
Downloads
51
Readme
Authentication Client Library
The Authentication Client Library is a Node.js wrapper for the Authentication API that makes it easier to code against the API. The library provides much of the supporting code needed to make HTTP requests and process HTTP responses.
The library is hosted on GitHub and Genesys welcomes pull requests for corrections.
Install
Genesys recommends that you install the Authentication Client Library for Node.js with NPM. Run the following command to install the library:
npm i genesys-authorization-client-js
Related Links
- Learn more about the Authentication API.
- Learn more about the Authentication Client Library.
Classes
The Authentication Client Library includes one main class, AuthenticationApi. This class contains all the resources and events that are part of the Authentication API, along with all the methods you need to access the API functionality.
Examples
Here's an example of how you can use the Authentication Client Library to authenticate using the Resource Owner Password Credentials Grant type.
const authorization = require('genesys-authorization-client-js');
const apiKey = "<apiKey>";
const apiUrl = "<apiUrl>";
const client = new authorization.ApiClient();
client.basePath = `${apiUrl}/auth/v3`;
client.defaultHeaders = {'x-api-key': apiKey};
client.enableCookies = true;
const agentUsername = "<agentUsername>";
const agentPassword = "<agentPassword>";
const clientId = "<clientId>";
const clientSecret = "<clientSecret>";
const authApi = new authorization.AuthenticationApi(client);
const opts = {
authorization: "Basic " + new Buffer(`${clientId}:${clientSecret}`).toString("base64"),
clientId: clientId,
scope: '*',
username: agentUsername,
password: agentPassword
};
authApi.retrieveTokenWithHttpInfo("password", opts).then(resp => {
const data = resp.response.body;
const accessToken = data.access_token;
if(!accessToken) {
throw new Error('Cannot get access token');
}
return accessToken;
}).then(token => {
//Initialize the API with token
// ...
}).catch(console.error);
For usage examples for each method available in the library, see the documentation for the AuthenticationAPi class.