Skip to content

Instantly share code, notes, and snippets.

@jauntyjocularjay
Last active June 28, 2024 10:23
Show Gist options
  • Save jauntyjocularjay/8c633500849f114eec4ace69e7c99942 to your computer and use it in GitHub Desktop.
Save jauntyjocularjay/8c633500849f114eec4ace69e7c99942 to your computer and use it in GitHub Desktop.
eBay.Auth
class Constant {
static ebay = {
api_scope: {
base: 'https://auth.sandbox.ebay.com/oauth2/authorize?client_id=:client_id&response_type=code&redirect_uri=Zapplugin-Zapplugi-zapplu-mgrkif&scope=https://api.ebay.com/oauth/api_scope',
default: 'https://api.ebay.com/oauth/api_scope',
buy: {
order_readonly:'https://api.ebay.com/oauth/api_scope/buy.order.readonly',
guest_order:'https://api.ebay.com/oauth/api_scope/buy.guest.order',
shopping_cart:'https://api.ebay.com/oauth/api_scope/buy.shopping.cart',
offer_auction:'https://api.ebay.com/oauth/api_scope/buy.offer.auction'
},
sell: {
marketing_readonly:'https://api.ebay.com/oauth/api_scope/sell.marketing.readonly',
marketing:'https://api.ebay.com/oauth/api_scope/sell.marketing',
inventory_readonly:'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
inventory:'https://api.ebay.com/oauth/api_scope/sell.inventory',
account_readonly:'https://api.ebay.com/oauth/api_scope/sell.account.readonly',
account:'https://api.ebay.com/oauth/api_scope/sell.account',
fulfillment_readonly:'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
fulfillment:'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
analytics_readonly:'https://api.ebay.com/oauth/api_scope/sell.analytics.readonly',
marketplace_insights_readonly:'https://api.ebay.com/oauth/api_scope/sell.marketplace.insights.readonly',
finances:'https://api.ebay.com/oauth/api_scope/sell.finances',
payment_dispute:'https://api.ebay.com/oauth/api_scope/sell.payment.dispute',
item_draft:'https://api.ebay.com/oauth/api_scope/sell.item.draft',
item:'https://api.ebay.com/oauth/api_scope/sell.item',
reputation:'https://api.ebay.com/oauth/api_scope/sell.reputation',
reputation_readonly:'https://api.ebay.com/oauth/api_scope/sell.reputation.readonly',
stores:'https://api.ebay.com/oauth/api_scope/sell.stores',
stores_readonly:'https://api.ebay.com/oauth/api_scope/sell.stores.readonly'
},
commerce: {
catalog_readonly:'https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly',
identity_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.readonly',
identity_email_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.email.readonly',
identity_phone_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.phone.readonly',
identity_address_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.address.readonly',
identity_name_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.name.readonly',
identity_status_readonly:'https://api.ebay.com/oauth/api_scope/commerce.identity.status.readonly',
notification_subscription:'https://api.ebay.com/oauth/api_scope/commerce.notification.subscription',
notification_subscription_readonly:'https://api.ebay.com/oauth/api_scope/commerce.notification.subscription.readonly',
}
},
sandbox: {
env: 'SANDBOX',
base_url: 'api.sandbox.ebay.com', //don't change these values
},
prod: {
env: 'PRODUCTION',
base_url: 'api.ebay.com', //don't change these values
},
countryCode: {
US: 'EBAY-US'
}
}
}
export {
Constant
}
import { default as EbayAuthToken } from 'ebay-oauth-nodejs-client'
import {
ENV,
Constant,
} from './index.mjs'
const isProd = false
let parameters
let env
if(isProd){
parameters = {
clientID: ENV.ebay.prod.clientID,
clientSecret: ENV.ebay.prod.clientSecret,
redirectUri: 'Zapplugin-Zapplugi-zapplu-mgrkif'
}
env = Constant.ebay.prod.env
} else {
parameters = {
clientID: ENV.ebay.sandbox.clientID,
clientSecret: ENV.ebay.sandbox.clientSecret,
redirectUri: 'Zapplugin-Zapplugi-zapplu-mgrkif',
env: Constant.ebay.sandbox.env,
baseUrl: Constant.ebay.sandbox.base_url
}
env = Constant.ebay.sandbox.env
}
const ebayAuthToken = new EbayAuthToken(parameters)
console.log('ebayAuthToken:', ebayAuthToken)
async function getApplicationToken(){
const token = await ebayAuthToken.getApplicationToken(env)
console.log(token)
}
await getApplicationToken()
// (async () => {
// const token = await ebayAuthToken.getApplicationToken(env)
// console.log(token)
// })()
(() => {
const authUrl = ebayAuthToken.generateUserAuthorizationUrl(env, Constant.ebay.api_scope.default)
console.log(authUrl)
})
(() => {
/**
* @constant {string} 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
*
*/
const options = { state: 'custom-state-value', prompt: 'login' }
const authURL = ebayAuthToken.generateUserAuthorizationUrl(env, Constant.ebay.api_scope.default, options)
})
(async () => {
const accessToken = await ebayAuthToken.exchangeCodeForAccessToken(env, code)
console.log(accessToken)
})()
(async () => {
const accessToken = await ebayAuthToken.getAccessToken(env, refresh_token, Constant.ebay.api_scope.default)
console.log(accessToken)
})()
export {
ebayAuthToken
}
import { ebayAuthToken } from '../components/ebay/index.mjs'
import {
throwsAnError,
did,
does,
have,
has,
is,
matches,
getCounter,
expectToBeTrue,
expectValuesToMatch,
objectsAreEquivalent,
expectObjectsAreEqual,
expectToBeNull,
throwsError,
expectConstructorToThrowError,
nullCheck,
} from '../module/chaitests/Chai.mjs'
async function GetAuthToken(){
console.log('ebayauthtoken:', ebayAuthToken)
}
await GetAuthToken()
$ mocha test --exit
ebayAuthToken: EbayOauthToken {
credentials: {
SANDBOX: {
clientID: ---,
clientSecret: ---,
redirectUri: ---,
env: 'SANDBOX',
baseUrl: 'api.sandbox.ebay.com'
}
},
grantType: ''
}
TypeError: getApplicationToken(...) is not a function
at file:///path/to/project/zapp/components/ebay/ebay.authtoken.mjs:45:1
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async formattedImport (path\to\AppData\Roaming\npm\node_modules\mocha\lib\nodejs\esm-utils.js:9:14)
at async exports.loadFilesAsync (path\to\AppData\Roaming\npm\node_modules\mocha\lib\nodejs\esm-utils.js:100:20)
at async singleRun (path\to\AppData\Roaming\npm\node_modules\mocha\lib\cli\run-helpers.js:125:3)
at async exports.handler (path\to\AppData\Roaming\npm\node_modules\mocha\lib\cli\run.js:370:5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment