hendt / ebay-api

eBay Node API in TypeScript for Node and Browser with RESTful and Traditional APIs. This library aims to implement all available eBay apis.
https://hendt.gitbook.io/ebay-api
MIT License
150 stars 40 forks source link

Has anyone gotten authorization_code grant flow to work? #128

Closed tariqazmat101 closed 1 year ago

tariqazmat101 commented 1 year ago

I am trying to get the authorization_code grant flow up and running but finding some issues.

  ebay:request postForm: https://api.ebay.com/identity/v1/oauth2/token +0ms
  ebay:oauth2 Failed to get the token Error: Request failed with status code 400
    at createError (/home/work/ebay-sold/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home//work/ebay-sold/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/home/work/ebay-sold/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  config: {
    url: 'https://api.ebay.com/identity/v1/oauth2/token',
    method: 'post',
    data: 'grant_type=authorization_code&code=v%255E1.1%2523i%255E1%2523I%255E3%2523p%25**********************************************RjUyQzI3QUVFMTc1NjFCMjcyMjA1RkQxOTEzRTVfMl8xI0VeMjYw&redirect_uri=****--sandbo-zgqwh',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/x-www-form-urlencoded',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'X-Requested-With, Origin, Content-Type, X-Auth-Token',
      'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE',
      'User-Agent': 'axios/0.21.4',
      'Content-Length': 226

The call is being sent correctly, so I believe the issue is on Ebay's side but I can't confirm.

Runame,devId,appId and certID are all correctly configured.

Here are the steps that I do:

  1. Generate the Auth URL

    const url = eBay.oAuth2.generateAuthUrl();
    console.log('Open URL', url);
    const token = await eBay.OAuth2.getToken("v%5E1.1%23i%5E1%23I%5E3%23p%5E3%23r%5E1%2**********************MThBRjUyQzI3QUVFMTc1NjFCMjcyMjA1RkQxOTEzRTVfMl8xI0VeMjYw");
  2. Authorize the consent request form generated by generateAuthurl()

  3. Consent form redirects me to https://google.ca (myredirectURI) where I extract the code and paste into GetToken()

tariqazmat101 commented 1 year ago

Ok I figured it out! Turns out the code returned by my redirecturi was percent encoded. You need to decode that to the true code and then plug that in into getToken(code)

https://meyerweb.com/eric/tools/dencoder/