Fetch Oauth token for Ebay developer REST Api's using node js.
[NOT MAINTAINED*] eBay officially published oauth module, kindly refer here https://github.com/eBay/ebay-oauth-nodejs-client]
npm install oauth-ebay
or
yarn add oauth-ebay
const ebayAuthToken = new EbayAuthToken({
clientId: "-- ClientID -- ", // required
clientSecret: "-- Client Secret --", // required
grantType: "-- Grant type --", // optional
scope: scopes, // array of scopes,
state: '', // optional
env: "PROD" // either SANDBOX or PROD (Default Value = PROD)
})
ebayAuthToken.getAccessToken().then((data) => {
console.log(data);
}).catch((error) => {
console.log(`Error to get Access token :${JSON.stringify(error)}`);
});
const ebayAuthToken = new EbayAuthToken({
clientId: "-- ClientID -- ", // required
clientSecret: "-- Client Secret --", // required
grantType: "-- Grant type --", // optional
scope: scopes,
redirectUri: "-- redirect uri app name --" // required for getting user consent url.
})
- Get User consent url
const userConsentUrl = ebayAuthToken.getUserConsentUrl();
- Open the userConsentUrl in the browser, which allows you to login in to ebay site. You will get a authorization code.
or if you are using express
use res.direct(userConsentUrl);
- pass the authorization code got in the above step to getAuthorizationCodeToken method
ebayAuthToken.getAuthorizationCodeToken(code).then((data) => {
console.log(data);
}).catch((error) => {
console.log(`Error to get Access token :${JSON.stringify(error)}`);
});
ebayAuthToken.getAccessTokenWithRefresh(refresh_token).then((data) => {
console.log(data);
}).catch((error) => {
console.log(`Error to get Access token from refresh token:${JSON.stringify(error)}`);
});
you can create issues or propose improvements here Click here
Getting Client Id and Client Secret
https://developer.ebay.com/api-docs/static/oauth-credentials.html
Getting your redirect_uri value
https://developer.ebay.com/api-docs/static/oauth-redirect-uri.html
Specifying right scopes
https://developer.ebay.com/api-docs/static/oauth-scopes.html