This SDK provides two Node.js modules to manage OAuth tokens:
getApiToken.js
: Fetches a token from the server and optionally handles retries.getApiTokenEncrypted.js
: Extends the functionality ofgetApiToken.js
by adding encryption and decryption of the token, and saving/loading the token to/from a file.
- Node.js 18 or higher.
node-fetch
library.dotenv
library (if using a.env
file).Consumer Key
,Consumer Secret
,OAuth Scope
,URL
to fetch token
- Clone the repository or download the SDK.
- Navigate to the project directory and run
npm install
to install the dependencies. - Set up your environment variables in a
.env
file
You must set the following environment variables for both modules:
CONSUMER_KEY
: Your consumer key.CONSUMER_SECRET
: Your consumer secret.URL
: The URL to fetch the token.SCOPE
: The scope for the token request.RETRIES
: Number of retries for fetching the token (optional).INTERVAL
: Interval between retries in milliseconds (optional).
For getApiTokenEncrypted.js
, you also need to provide:
TOKEN_PATH
: The path to the file where the encrypted token will be saved.
You can create a .env
file in the root directory to load these variables.
You can run the tests locally using Jest:
npm test
You can import the refreshToken
function from getApiToken.js
and call it to fetch a token:
const { refreshToken } = require('../src/getApiToken');
const tokenData = await refreshToken();
// Your code here
This module provides additional functions to encrypt and decrypt data and to save and load encrypted tokens to/from a file:
const { refreshToken } = require('../src/getApiTokenEncrypted');
const tokenData = await refreshToken();
// Your code here
For more information, please refer to the Documentation
folder in this repository.
Feel free to open issues or submit pull requests if you find any problems or have suggestions.
These modules are licensed under the GPLv3. Please see the LICENSE file in the root directory for more information.
- Patrick Roch