token-nxg-cg
v1.0.1
Published
A library for generating access tokens
Downloads
7
Readme
Token Generator
Token Generator is a Node.js library for generating access tokens using client credentials.
Installation
To install the Token Generator library, run:
npm install tokengenerator
Usage
const TokenConnector = require('token-nxg-cg');
// Replace these values with your actual client ID, client secret, and token URL
const clientId = 'your_client_id';
const clientSecret = 'your_client_secret';
const tokenUrl = 'https://example.com/token'; // Replace with your token URL
async function getToken() {
try {
const connector = new TokenConnector(clientId, clientSecret, tokenUrl);
const accessToken = await connector.getAccessToken();
console.log('Access Token:', accessToken);
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
}
}
getToken();
Constructor
new TokenConnector(clientId, clientSecret, tokenUrl)
clientId (string): The client ID provided by the OAuth provider.
clientSecret (string): The client secret provided by the OAuth provider.
tokenUrl (string): The token URL where the access token will be requested
Methods
getAccessToken()
Retrieves an access token using client credentials.
Returns: A Promise that resolves with the access token string