- Notifications
You must be signed in to change notification settings - Fork30
🔑 Generate an OAuth token that can be used to call the eBay Developer REST APIs.
License
eBay/ebay-oauth-nodejs-client
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This code allows developers to fetch an OAuth token that can be used to call the eBay Developer REST APIs. The code is intended for use with Node.js.
- What is OAuth 2.0
- Installation
- Library Setup and getting started
- Configure credentials
- Types of Tokens
- Supported Grant Types for OAuth
- References
- License
OAuth 2.0 is the most widely used standard for authentication and authorization for API based access. The complete end to end documentation on how eBay OAuth functions may be used is available at developer.ebay.com.See:https://developer.ebay.com/api-docs/static/oauth-tokens.html
Using npm:
npm install ebay-oauth-nodejs-client
Using yarn:
yarn add ebay-oauth-nodejs-client
Create a new instance ofEbayAuthToken with a relevant config.
constEbayAuthToken=require('ebay-oauth-nodejs-client');constebayAuthToken=newEbayAuthToken({clientId:'<your_client_id>',clientSecret:'<your_client_secret>',redirectUri:'<redirect uri>'});
Generate client credential token.
(async()=>{consttoken=awaitebayAuthToken.getApplicationToken('PRODUCTION');console.log(token);})();
Generate user consent authorization url.
(()=>{constauthUrl=ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION',scopes);console.log(authUrl);})();
You can also provide optional values:
state: An opaque value used by the client to maintain state between the request and callback.
prompt: Force a user to log in when you redirect them to the Grant Application Access page, even if they already have an existing user session.
The method call above could also be done as
(()=>{constoptions={state:'custom-state-value',prompt:'login'};constauthUrl=ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION',scopes,options);console.log(authUrl);})();
Getting a User access token.
(async()=>{constaccessToken=awaitebayAuthToken.exchangeCodeForAccessToken('PRODUCTION',code);console.log(accessToken);})();
Using a refresh token to update a User access token (Updating the expired access token).
(async()=>{constaccessToken=awaitebayAuthToken.getAccessToken('PRODUCTION',refreshToken,scopes);console.log(accessToken);})();
- Invoke the oauth ebay library as given below
constEbayAuthToken=require('ebay-oauth-nodejs-client');constebayAuthToken=newEbayAuthToken({filePath:'demo/eBayJson.json'// input file path.})
OR
constebayAuthToken=newEbayAuthToken({clientId:'<your_client_id>',clientSecret:'<your_client_secret>',redirectUri:'<redirect_uri_name>'});
- If you want to get your application credentials such as AppId, DevId, and CertId. Refer toCreating eBay Developer Account for details on how to get these credentials.
- You can refer to example.js for an example of how to use credentials.
- For Authorization code grant
- Get User consent url using
ebayAuthToken.generateUserAuthorizationUrl() - Open the generateUserAuthorizationUrl 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(generateUserAuthorizationUrl); - Pass the authorization code retrieved in the above step to exchangeCodeForAccessToken method using
ebayAuthToken.exchangeCodeForAccessToken(environment, code)
- Get User consent url using
Create a config JSON file in your application. The config file should contain your eBay applications keys: App Id, Cert Id & Dev Id. A sample config file is available at demo/ebay-config-sample.json. Learn more about creating application keys.
{"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 }}There are mainly two types of tokens in usage.
An application token contains an application identity which is generated using client_credentials grant type. These application tokens are useful for interaction with application specific APIs such as usage statistics etc.,
A user token (access token or refresh token) contains a user identity and the application’s identity. This is usually generated using the authorization_code grant type or the refresh_token grant type.
All of the regular OAuth 2.0 specifications such as client_credentials, authorization_code, and refresh_token are supported.Refer to eBay Developer Portal
This grant type can be performed by simply usingebayAuthToken.getApplicationToken(). Read more about this grant type atoauth-client-credentials-grant.
This grant type can be performed by a two step process. CallebayAuthToken.generateUserAuthorizationUrl(environment, scopes, state) to get the Authorization URL to redirect the user to. Once the user authenticates and approves the consent, the callback needs to be captured by the redirect URL setup by the app and then callebayAuthToken.exchangeCodeForAccessToken(environment, code) to get the refresh and access tokens.
Read more about this grant type atoauth-authorization-code-grant.
This grant type can be performed by simply usingebayAuthToken.getAccessToken(environment, refreshToken, scopes). Usually access tokens are short lived and if the access token is expired, the caller can use the refresh token to generate a new access token. Read more about it atUsing a refresh token to update a user access token
you've found an bug/issue, please file it onGitHub.
https://developer.ebay.com/api-docs/static/oauth-tokens.html
https://developer.ebay.com/api-docs/static/oauth-quick-ref-user-tokens.html
https://developer.ebay.com/api-docs/static/oauth-gen-app-token.html
Copyright (c) 2019 eBay Inc.
Use of this source code is governed by a Apache-2.0 license that can be found in the LICENSE file or athttps://opensource.org/licenses/Apache-2.0.
- 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
About
🔑 Generate an OAuth token that can be used to call the eBay Developer REST APIs.
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors5
Uh oh!
There was an error while loading.Please reload this page.