### Install Library via npm (Shell) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Use the npm package manager to install the `ebay-oauth-nodejs-client` library as a project dependency. ```shell npm install ebay-oauth-nodejs-client ``` -------------------------------- ### Install Library via yarn (Shell) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Use the yarn package manager to install the `ebay-oauth-nodejs-client` library as a project dependency. ```shell yarn add ebay-oauth-nodejs-client ``` -------------------------------- ### Get Application Token (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Asynchronously fetch an application access token using the client credentials grant type. Specify the eBay environment ('PRODUCTION' or 'SANDBOX'). The resulting token is logged to the console. ```javascript (async () => { const token = await ebayAuthToken.getApplicationToken('PRODUCTION'); console.log(token); })(); ``` -------------------------------- ### Initialize Client with File Path (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Create a new instance of `EbayAuthToken` by providing the file path to a JSON configuration file containing your eBay credentials. This is an alternative to providing credentials inline. ```javascript const EbayAuthToken = require('ebay-oauth-nodejs-client'); const ebayAuthToken = new EbayAuthToken({ filePath: 'demo/eBayJson.json' // input file path. }) ``` -------------------------------- ### Initialize Client with Inline Config (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Create a new instance of `EbayAuthToken` by passing an object containing your eBay `clientId`, `clientSecret`, and `redirectUri` directly. This is an alternative to using a configuration file. ```javascript const ebayAuthToken = new EbayAuthToken({ clientId: '', clientSecret: '', redirectUri: '' }); ``` -------------------------------- ### Initialize Client with Credentials (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Create a new instance of the EbayAuthToken class by passing an object containing your eBay `clientId`, `clientSecret`, and `redirectUri` directly. This configures the client for making OAuth requests. ```javascript const EbayAuthToken = require('ebay-oauth-nodejs-client'); const ebayAuthToken = new EbayAuthToken({ clientId: '', clientSecret: '', redirectUri: '' }); ``` -------------------------------- ### Generate User Auth URL (Options) (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generate the user authorization URL including optional parameters like `state` to maintain context and `prompt` to force login. Provide the environment, scopes, and an options object. ```javascript (() => { const options = { state: 'custom-state-value', prompt: 'login' }; const authUrl = ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION', scopes, options); console.log(authUrl); })(); ``` -------------------------------- ### Generate User Auth URL (Basic) (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generate the URL required to redirect a user to eBay's site for granting your application access. Provide the environment and an array of required scopes. ```javascript (() => { const authUrl = ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION', scopes); console.log(authUrl); })(); ``` -------------------------------- ### Configure eBay OAuth Credentials JSON Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md This JSON configuration file stores the necessary eBay application keys (Client ID, Client Secret, Dev ID) and redirect URI for both the SANDBOX and PRODUCTION environments. This file is used by the Node.js client to authenticate with the eBay API. ```json { "SANDBOX": { "clientId": "---Client Id---", "clientSecret": "--- client secret---", "devid": "-- dev id ---", "redirectUri": "-- redirect uri ---", "baseUrl": "api.sandbox.ebay.com" //don't change these values }, "PRODUCTION": { "clientId": "---Client Id---", "clientSecret": "--- client secret---", "devid": "-- dev id ---", "redirectUri": "-- redirect uri ---", "baseUrl": "api.ebay.com" //don't change these values } } ``` -------------------------------- ### Refresh User Access Token (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Use a valid refresh token to obtain a new user access token and potentially a new refresh token. This is necessary when the current access token expires to maintain user session access. ```javascript (async () => { const accessToken = await ebayAuthToken.getAccessToken('PRODUCTION', refreshToken, scopes); console.log(accessToken); })(); ``` -------------------------------- ### Exchange Code for Access Token (Node.js) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Exchange the authorization code obtained after user consent for a user access token and refresh token. This token allows your application to make API calls on behalf of the user. ```javascript (async () => { const accessToken = await ebayAuthToken.exchangeCodeForAccessToken('PRODUCTION', code); console.log(accessToken); })(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.