Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ebay-oauth-nodejs-client
Advanced tools
Readme
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.
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 of EbayAuthToken
with a relevant config.
const EbayAuthToken = require('ebay-oauth-nodejs-client');
const ebayAuthToken = new EbayAuthToken({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
redirectUri: '<redirect uri>'
});
Generate client credential token.
(async () => {
const token = await ebayAuthToken.getApplicationToken('PRODUCTION');
console.log(token);
})();
Generate user consent authorization url.
(() => {
const authUrl = 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
(() => {
const options = { state: 'custom-state-value', prompt: 'login' };
const authUrl = ebayAuthToken.generateUserAuthorizationUrl('PRODUCTION', scopes, options);
console.log(authUrl);
})();
Getting a User access token.
(async () => {
const accessToken = await ebayAuthToken.exchangeCodeForAccessToken('PRODUCTION', code);
console.log(accessToken);
})();
Using a refresh token to update a User access token (Updating the expired access token).
(async () => {
const accessToken = await ebayAuthToken.getAccessToken('PRODUCTION', refreshToken, scopes);
console.log(accessToken);
})();
const EbayAuthToken = require('ebay-oauth-nodejs-client');
const ebayAuthToken = new EbayAuthToken({
filePath: 'demo/eBayJson.json' // input file path.
})
OR
const ebayAuthToken = new EbayAuthToken({
clientId: '<your_client_id>',
clientSecret: '<your_client_secret>',
redirectUri: '<redirect_uri_name>'
});
ebayAuthToken.generateUserAuthorizationUrl()
res.direct(generateUserAuthorizationUrl);
ebayAuthToken.exchangeCodeForAccessToken(environment, code)
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 using ebayAuthToken.getApplicationToken()
. Read more about this grant type at oauth-client-credentials-grant.
This grant type can be performed by a two step process. Call ebayAuthToken.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 call ebayAuthToken.exchangeCodeForAccessToken(environment, code)
to get the refresh and access tokens.
Read more about this grant type at oauth-authorization-code-grant.
This grant type can be performed by simply using ebayAuthToken.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 at Using a refresh token to update a user access token
you've found an bug/issue, please file it on GitHub.
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 at https://opensource.org/licenses/Apache-2.0.
FAQs
Get oauth2 token for ebay developer application
The npm package ebay-oauth-nodejs-client receives a total of 4,770 weekly downloads. As such, ebay-oauth-nodejs-client popularity was classified as popular.
We found that ebay-oauth-nodejs-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.