### Basic getApplicationToken call and parsing Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Example of initializing the client and performing a basic call to get an application token, followed by parsing the JSON response. ```js const EbayOauthToken = require('ebay-oauth-nodejs-client'); const client = new EbayOauthToken({ clientId: 'your-client-id', clientSecret: 'your-client-secret', redirectUri: 'https://example.com/auth/callback' }); (async () => { const body = await client.getApplicationToken('PRODUCTION'); // default client-credential scope const { access_token, expires_in, token_type } = JSON.parse(body); console.log(token_type, access_token, expires_in); })(); ``` -------------------------------- ### Example: inline credentials (defaults to PRODUCTION) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Creates a client with inline credentials. The environment defaults to PRODUCTION, and the baseUrl is derived accordingly. ```javascript const EbayOauthToken = require('ebay-oauth-nodejs-client'); const client = new EbayOauthToken({ clientId: 'your-client-id', clientSecret: 'your-client-secret', redirectUri: 'https://example.com/auth/callback' }); ``` -------------------------------- ### Install with npm Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Install the ebay-oauth-nodejs-client package using npm. ```shell npm install ebay-oauth-nodejs-client ``` -------------------------------- ### Install with yarn Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Install the ebay-oauth-nodejs-client package using yarn. ```shell yarn add ebay-oauth-nodejs-client ``` -------------------------------- ### Example — basic URL Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Shows how to create a client and generate a basic authorization URL with scopes. The resulting URL is logged as a comment. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); const scopes = [ 'https://api.ebay.com/oauth/api_scope/sell.inventory', 'https://api.ebay.com/oauth/api_scope/sell.marketing' ]; const authUrl = client.generateUserAuthorizationUrl('PRODUCTION', scopes); // https://auth.ebay.com/oauth2/authorize?client_id=...&redirect_uri=...&response_type=code&scope=... ``` -------------------------------- ### Example — with state/prompt options and error handling Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Demonstrates passing prompt and state options, and handling errors. Shows that passing a string for options throws an error with message 'Improper way to provide optional values'. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); try { const url = client.generateUserAuthorizationUrl('PRODUCTION', scopes, { prompt: 'login', state: 'custom-state-value' }); console.log(url); } catch (err) { console.error('Failed to build authorization URL:', err.message); } // Options must be an object — otherwise: try { client.generateUserAuthorizationUrl('PRODUCTION', scopes, 'options'); } catch (err) { console.error(err.message); // "Improper way to provide optional values" } ``` -------------------------------- ### Resulting instance shape example Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/configuration.md Example of the resulting instance shape after constructing EbayOauthToken with options. Verified by test/test.js. ```json { "PRODUCTION": { "clientId": "PROD1234ABCD", "clientSecret": "PRODSSSXXXZZZZ", "devid": "SANDBOXDEVID", "env": "PRODUCTION", "baseUrl": "api.ebay.com" } } ``` -------------------------------- ### Authorization URL example Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/endpoints.md Example authorization URL generated by generateUserAuthorizationUrl for the production environment. The query parameters are constructed in order: client_id, redirect_uri, response_type=code, scope, and optional prompt and state. This URL is meant to be opened in a browser to start the OAuth authorization-code flow. ```text https://auth.ebay.com/oauth2/authorize?client_id=PROD1234ABCD&redirect_uri=PRODREDIRECT&response_type=code&scope=https://api.ebay.com/oauth/api_scope&prompt=login&state=state ``` -------------------------------- ### Basic exchange example Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Shows how to call exchangeCodeForAccessToken with a valid authorization code, parse the JSON response, and access the access_token and refresh_token properties. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); (async () => { const body = await client.exchangeCodeForAccessToken('PRODUCTION', 'the-authorization-code'); const tokens = JSON.parse(body); console.log('access_token:', tokens.access_token); console.log('refresh_token:', tokens.refresh_token); // store long-term })(); ``` -------------------------------- ### Example: credentials from a JSON file, and the missing-options error Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Shows creating a client from a JSON file and catching the error thrown when options are missing. The error message is 'This method accepts an object with filepath or with client id and client secret'. ```javascript const EbayOauthToken = require('ebay-oauth-nodejs-client'); const fromFile = new EbayOauthToken({ filePath: 'config/ebay-credentials.json' }); try { new EbayOauthToken(); // eslint-disable-line no-new } catch (err) { console.error(err.message); // "This method accepts an object with filepath or with client id and client secret" } ``` -------------------------------- ### getApplicationToken with explicit scopes and error handling Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Example of requesting a token with specific scopes and handling potential errors using promise chains. ```js const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); client.getApplicationToken('SANDBOX', ['https://api.ebay.com/oauth/api_scope/sell.inventory']) .then((body) => { console.log(JSON.parse(body).access_token); }) .catch((err) => { // Caught here: transport errors and synchronous throws propagate. console.error('Token request failed:', err); }); ``` -------------------------------- ### Get application token with getApplicationToken Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generates a client credential token for the specified environment (e.g., 'PRODUCTION'). ```javascript (async () => { const token = await ebayAuthToken.getApplicationToken('PRODUCTION'); console.log(token); })(); ``` -------------------------------- ### setRefreshToken usage example Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Creates an EbayOauthToken client and calls setRefreshToken with a sample token, then logs the stored token using getRefreshToken. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); client.setRefreshToken('v^1.1#...'); console.log(client.getRefreshToken()); // 'v^1.1#...' ``` -------------------------------- ### getRefreshToken usage example Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Creates a client, sets a refresh token, retrieves it, and checks if it exists before proceeding to obtain one via exchangeCodeForAccessToken if not. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); client.setRefreshToken('v^1.1#...'); const token = client.getRefreshToken(); if (!token) { // obtain one via exchangeCodeForAccessToken first } ``` -------------------------------- ### Example: pass refresh token explicitly Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Shows how to call getAccessToken with an explicit refresh token and log the resulting access token. The refresh token is passed as the second argument, and scopes are provided as an array. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); (async () => { const body = await client.getAccessToken( 'PRODUCTION', 'v^1.1#i^1#r^1#f^0...', // refresh token from exchangeCodeForAccessToken ['https://api.ebay.com/oauth/api_scope/sell.inventory'] ); console.log(JSON.parse(body).access_token); })(); ``` -------------------------------- ### Example: stored refresh token used as fallback Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Demonstrates using a stored refresh token via setRefreshToken, then calling getAccessToken with a null refreshToken argument to fall back to the stored token. Includes error handling for when no token is stored. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); client.setRefreshToken(storedRefreshToken); client.getAccessToken('PRODUCTION', null, scopes) // refreshToken arg may be omitted/empty .then((body) => console.log(JSON.parse(body))) .catch((err) => console.error(err.message)); // "Refresh token is required, ..." when none was stored either ``` -------------------------------- ### Example with catch for required-code error Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Demonstrates error handling when the authorization code is null. The promise rejects with an error message 'Authorization code is required'. ```javascript const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); client.exchangeCodeForAccessToken('PRODUCTION', null) .then((body) => console.log(body)) .catch((err) => console.error(err.message)); // "Authorization code is required" ``` -------------------------------- ### Sample eBay config JSON Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Sample configuration file for eBay application keys. Contains SANDBOX and PRODUCTION environments with clientId, clientSecret, devid, redirectUri, and baseUrl. The baseUrl values should not be changed. ```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 } } ``` -------------------------------- ### constructor(options) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Constructor for the EbayOauthToken class. Initializes the instance with credentials from a file or inline options. ```APIDOC ## constructor(options) ### Description Creates an EbayOauthToken instance with the provided credentials. Accepts either a file path to a JSON credentials file or inline credentials object. ### Method constructor ### Parameters - **options** (object) - Required - Either `{ filePath }` or inline credentials `{ clientId, clientSecret, redirectUri, ... }` ### Request Example ```js const client = new EbayOauthToken({ clientId: 'your-client-id', clientSecret: 'your-client-secret', redirectUri: 'https://example.com/auth/callback' }); ``` ### Response Returns the EbayOauthToken instance. ### Error Handling - **Error** - Thrown when `options` is missing/undefined: "This method accepts an object with filepath or with client id and client secret" ``` -------------------------------- ### Require and instantiate EbayOauthToken Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md Shows how to require the package and create a client instance with clientId, clientSecret, and redirectUri. The README uses the local name EbayAuthToken, but the exported class is EbayOauthToken. ```javascript const EbayOauthToken = require('ebay-oauth-nodejs-client'); // → class (src/index.js:138) const client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); ``` -------------------------------- ### Instantiate EbayAuthToken with config Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Creates an EbayAuthToken instance with client credentials and redirect URI. Required before using any token methods. ```javascript const EbayAuthToken = require('ebay-oauth-nodejs-client'); const ebayAuthToken = new EbayAuthToken({ clientId: '', clientSecret: '', redirectUri: '' }); ``` -------------------------------- ### Initialize EbayAuthToken with client credentials Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Initializes the eBay OAuth client by providing clientId, clientSecret, and redirectUri directly. This is an alternative to using a filePath. ```javascript const ebayAuthToken = new EbayAuthToken({ clientId: '', clientSecret: '', redirectUri: '' }); ``` -------------------------------- ### Initialize EbayAuthToken with filePath Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Initializes the eBay OAuth client by loading credentials from a JSON file. The filePath should point to a configuration file containing your eBay application keys. ```javascript const EbayAuthToken = require('ebay-oauth-nodejs-client'); const ebayAuthToken = new EbayAuthToken({ filePath: 'demo/eBayJson.json' // input file path. }) ``` -------------------------------- ### Constructor implementation Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md The constructor validates the options object, throws an error if missing, and initializes credentials and grantType. It returns the instance explicitly. ```javascript constructor(options) { if (!options) { throw new Error('This method accepts an object with filepath or with client id and client secret'); } // get user credentials. this.credentials = options.filePath ? readJSONFile(options.filePath) : readOptions(options); this.grantType = ''; return this; } ``` -------------------------------- ### EbayAuthToken(config) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Constructor for creating a new EbayAuthToken instance with client credentials and redirect URI. ```APIDOC ## EbayAuthToken(config) ### Description Creates a new instance of the EbayAuthToken client with the provided configuration. ### Method Constructor ### Parameters - **config** (object) - Required - Configuration object containing clientId, clientSecret, and redirectUri. - **clientId** (string) - Required - Your eBay application client ID. - **clientSecret** (string) - Required - Your eBay application client secret. - **redirectUri** (string) - Required - The redirect URI used in the OAuth flow. ### Example ```js const EbayAuthToken = require('ebay-oauth-nodejs-client'); const ebayAuthToken = new EbayAuthToken({ clientId: '', clientSecret: '', redirectUri: '' }); ``` ``` -------------------------------- ### getApplicationToken method implementation Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md The internal implementation of the getApplicationToken method, showing how it validates parameters and constructs the POST request. ```js getApplicationToken(environment, scopes = consts.CLIENT_CRED_SCOPE) { validateParams(environment, scopes, this.credentials); this.grantType = consts.PAYLOAD_VALUE_CLIENT_CREDENTIALS; // 'client_credentials' this.scope = Array.isArray(scopes) ? scopes.join('%20') : scopes; const data = queryString.stringify({ grant_type: this.grantType, scope: this.scope }); return postRequest(data, this.credentials[environment]); } ``` -------------------------------- ### Credentials file format for filePath Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/configuration.md Sample credentials file for the eBay OAuth Node.js client, used with the filePath option. Top-level keys must match the environment argument passed to methods. The file is parsed with JSON.parse(fs.readFileSync(resolvedPath)) and used as this.credentials as-is, with no merging or fallback. ```json { "SANDBOX": { "clientId": "---Client Id---", "clientSecret": "--- client secret---", "devid": "-- dev id ---", "redirectUri": "-- redirect uri ---", "baseUrl": "api.sandbox.ebay.com" }, "PRODUCTION": { "clientId": "---Client Id---", "clientSecret": "--- client secret---", "devid": "-- dev id ---", "redirectUri": "-- redirect uri ---", "baseUrl": "api.ebay.com" } } ``` -------------------------------- ### readOptions function in src/utils.js Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/configuration.md Internal helper that processes the constructor options object. It defaults the env to 'PRODUCTION', derives the baseUrl from the env, and stores the options under the env key in the credentials object. ```javascript const readOptions = (options) => { const credentials = {}; if (!options.env) options.env = 'PRODUCTION'; options.baseUrl = options.env === 'PRODUCTION' ? prodBaseUrl : sandboxBaseUrl; credentials[options.env] = { ...options }; return credentials; }; ``` -------------------------------- ### getApplicationToken Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/types.md Documentation for the `getApplicationToken` method, which obtains an application access token. ```APIDOC ## `getApplicationToken` ### Description Retrieves an application access token (client credentials flow). Returns the raw token response as an unparsed JSON string. ### Response Returns a Promise that resolves with the raw token response body (JSON string). The response contains fields such as `access_token`, `expires_in`, `token_type`, and possibly `error` fields. ``` -------------------------------- ### ebayAuthToken.getApplicationToken(environment) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generates a client credentials token for the specified environment. ```APIDOC ## ebayAuthToken.getApplicationToken(environment) ### Description Generates a client credentials token for the specified environment. ### Method Async method ### Parameters - **environment** (string) - Required - The environment to use, e.g., 'PRODUCTION'. ### Returns - **token** (string) - The application access token. ### Example ```js (async () => { const token = await ebayAuthToken.getApplicationToken('PRODUCTION'); console.log(token); })(); ``` ``` -------------------------------- ### generateUserAuthorizationUrl(environment, scopes, options) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/types.md Documentation for the `generateUserAuthorizationUrl` method, which constructs the eBay OAuth authorization URL. ```APIDOC ## `generateUserAuthorizationUrl(environment, scopes, options)` ### Description Generates the eBay OAuth user authorization URL for the given environment and scopes. Optional `prompt` and `state` parameters can be passed to control the authorization flow. ### Parameters - **environment** (string) - Required - The eBay environment (e.g., 'PRODUCTION' or 'SANDBOX'). - **scopes** (array of strings) - Required - The OAuth scopes to request. - **options** (object) - Optional - An object containing optional parameters. - **prompt** (string) - Optional - OAuth `prompt` parameter; `'login'` forces a login even with an existing user session. - **state** (string) - Optional - Opaque value used to maintain state between the request and the callback. ### Notes - Only truthy values are appended to the URL: `prompt ? ...&prompt=${prompt}` and `state ? ...&state=${state}`. - Passing a non-object (e.g., a string) throws `'Improper way to provide optional values'`. ``` -------------------------------- ### Generate user authorization URL with options Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generates a user authorization URL with optional state and prompt parameters. The state is an opaque value for maintaining state; prompt forces login even with an existing session. ```javascript (() => { const options = { state: 'custom-state-value', prompt: 'login' }; const authUrl = ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION', scopes, options); console.log(authUrl); })(); ``` -------------------------------- ### generateUserAuthorizationUrl method implementation Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md The method implementation that validates parameters, constructs the authorization URL, and returns it. It throws errors for invalid environment, scopes, credentials, missing redirectUri, or improper options. ```javascript generateUserAuthorizationUrl(environment, scopes, options) { validateParams(environment, scopes, this.credentials); const credentials = this.credentials[environment]; if (!credentials) throw new Error('Error while reading the credentials, Kindly check here to configure'); if (!credentials.redirectUri) throw new Error('redirect_uri is required for redirection after sign in \n kindly check here https://developer.ebay.com/api-docs/static/oauth-redirect-uri.html'); if (options && typeof(options) !== 'object') throw new Error('Improper way to provide optional values'); this.scope = Array.isArray(scopes) ? scopes.join('%20') : scopes; const { prompt, state } = options || {}; let queryParam = `client_id=${credentials.clientId}`; queryParam = `${queryParam}&redirect_uri=${credentials.redirectUri}`; queryParam = `${queryParam}&response_type=code`; queryParam = `${queryParam}&scope=${this.scope}`; queryParam = prompt ? `${queryParam}&prompt=${prompt}` : queryParam; queryParam = state ? `${queryParam}&state=${state}` : queryParam; const baseUrl = environment === 'PRODUCTION' ? consts.OAUTHENVIRONMENT_WEBENDPOINT_PRODUCTION : consts.OAUTHENVIRONMENT_WEBENDPOINT_SANDBOX; return `${baseUrl}?${queryParam}`; } ``` -------------------------------- ### Catch errors from ebay-oauth-nodejs-client Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/errors.md Shows how to catch errors thrown by the eBay OAuth client. The constructor throws when no options object is passed (#1). The getApplicationToken call can throw synchronously for validation errors (#2/#3/#4) or unknown environment (#12), while transport failures are rejected promises (#10). The response body is a raw string that can be parsed to check for OAuth-level errors like invalid_grant or invalid_client. ```javascript const EbayOauthToken = require('ebay-oauth-nodejs-client'); let client; try { client = new EbayOauthToken({ clientId, clientSecret, redirectUri }); } catch (err) { // #1 — no options object passed console.error(err.message); } try { client.getApplicationToken('PRODUCTION') .then((body) => { const parsed = JSON.parse(body); // body is the raw string (#11/#endpoints) if (parsed.error) { // OAuth-level failure: invalid_grant, invalid_client, ... } }) .catch((err) => { // #10 — transport-level failure console.error('transport error:', err); }); } catch (err) { // #2/#3/#4 synchronous validation errors, or #12 unknown environment console.error('synchronous error:', err.message); } ``` -------------------------------- ### postRequest(data, ebayAuthToken) Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/types.md Documentation for the `postRequest` method, which performs the OAuth token request. ```APIDOC ## `postRequest(data, ebayAuthToken)` ### Description Sends an HTTP request to the eBay OAuth token endpoint. Requires `clientId`, `clientSecret`, and `baseUrl` from the credentials entry to construct the Basic auth header and request hostname. Resolves with the raw response body as a string; consumers must parse it themselves. ### Parameters - **data** (object) - Required - The request payload (e.g., grant type, code, refresh token). - **ebayAuthToken** (string) - Required - The eBay auth token used for authentication. ### Response Resolves with the raw body string. The Promise resolves for any HTTP status; consumers must inspect the parsed body for `error` themselves. ``` -------------------------------- ### exchangeCodeForAccessToken method implementation Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md The core implementation of exchangeCodeForAccessToken. It validates the code and environment, constructs the request payload with grant_type=authorization_code, and posts the request. Throws an error if code is empty. ```javascript exchangeCodeForAccessToken(environment, code) { if (!code) { throw new Error('Authorization code is required'); } validateParams(environment, true, this.credentials[environment]); const credentials = this.credentials[environment]; const data = `code=${code}&grant_type=${consts.PAYLOAD_VALUE_AUTHORIZATION_CODE}&redirect_uri=${credentials.redirectUri}`; return postRequest(data, credentials); } ``` -------------------------------- ### src/request.js module with postRequest and base64Encode Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/internal-modules.md The module exports postRequest, which sends a POST request to the eBay OAuth token endpoint. It uses base64Encode to create the Basic authorization header from clientId and clientSecret. The Promise always resolves with the raw response body string, even on HTTP errors, because body.error is always falsy on a string. Rejects with transport errors and throws synchronously if ebayAuthToken is falsy. ```javascript const base64Encode = (encodeData) => { const buff = new Buffer.from(encodeData); return buff.toString('base64'); }; const postRequest = (data, ebayAuthToken) => { ... }; module.exports = postRequest; ``` -------------------------------- ### getAccessToken Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/types.md Documentation for the `getAccessToken` method, which obtains an access token using a refresh token. ```APIDOC ## `getAccessToken` ### Description Retrieves an access token using a refresh token (refresh token flow). Returns the raw token response as an unparsed JSON string. ### Response Returns a Promise that resolves with the raw token response body (JSON string). The response may include `access_token`, `expires_in`, `token_type`, `refresh_token`, `refresh_token_expires_in`, and error fields. ``` -------------------------------- ### Generate user authorization URL with generateUserAuthorizationUrl Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/README.md Generates a user consent authorization URL with the given scopes. Optional parameters can be provided as a third argument. ```javascript (() => { const authUrl = ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION', scopes); console.log(authUrl); })(); ``` -------------------------------- ### getAccessToken method implementation Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/api-reference/ebayoauth-token.md The core implementation of getAccessToken, which validates parameters, constructs the OAuth token request payload, and posts it to the token endpoint. It throws an error if no refresh token is available. ```javascript getAccessToken(environment, refreshToken, scopes) { const token = refreshToken || this.getRefreshToken(); validateParams(environment, scopes, this.credentials); this.scope = Array.isArray(scopes) ? scopes.join('%20') : scopes; if (!token) { throw new Error('Refresh token is required, to generate refresh token use exchangeCodeForAccessToken method'); } const data = `refresh_token=${token}&grant_type=${consts.PAYLOAD_REFRESH_TOKEN}&scope=${this.scope}`; return postRequest(data, this.credentials[environment]); } ``` -------------------------------- ### exchangeCodeForAccessToken Source: https://github.com/ebay/ebay-oauth-nodejs-client/blob/master/_autodocs/types.md Documentation for the `exchangeCodeForAccessToken` method, which exchanges an authorization code for tokens. ```APIDOC ## `exchangeCodeForAccessToken` ### Description Exchanges an authorization code for an access token (authorization code flow). Returns the raw token response as an unparsed JSON string. ### Response Returns a Promise that resolves with the raw token response body (JSON string). The response may include `access_token`, `expires_in`, `token_type`, `refresh_token`, `refresh_token_expires_in`, and error fields. ```