Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth token not refreshed #164

Open
4 of 6 tasks
nrathi opened this issue Mar 22, 2024 · 6 comments
Open
4 of 6 tasks

Auth token not refreshed #164

nrathi opened this issue Mar 22, 2024 · 6 comments
Assignees

Comments

@nrathi
Copy link

nrathi commented Mar 22, 2024

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?

Describe the bug
I believe I have a use case where the token should automatically get refreshed, but it is not.

Code

   const response =
      await this.api.trading.GetMyeBaySelling?.(
        {
          SoldList: {
            DurationInDays: 60,
            Include: true,
            OrderStatusFilter: "All",
            Sort: "EndTimeDescending",
          },
        },
        { useIaf: true },
      );

Output

 "error": "{\n  \"stack\": \"EbayApiError: Auth token is hard expired.\\n    at checkEBayResponse (/home/johndoe/myapp/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/errors/index.js:187:15)\\n    at XMLRequest.request (/home/johndoe/myapp/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/XMLRequest.js:118:46)\\n    at runMicrotasks (<anonymous>)\\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\\n    at async Traditional.request (/home/johndoe/myapp/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/index.js:178:20)\\n    at async Object.GetMyeBaySelling (/home/johndoe/myapp/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/index.js:44:24)\",\n  \"message\": \"Auth token is hard expired.\",\n  \"description\": \"Auth token is hard expired, User needs to generate a new token for this application.\",\n  \"meta\": {}\n}",

expected data

This error self-resolves, so I think it has to do with the token not being refreshed, and then some other call down the line does the refresh. https://community.ebay.com/t5/eBay-APIs-Talk-to-your-fellow/get-a-new-auth-token-where-do-i-go-to-get-it/td-p/33655751

Would you like to work on this issue?

  • Yes
  • No
  • Maybe
@nrathi
Copy link
Author

nrathi commented Mar 28, 2024

Hey @dantio, do you have time to take this on? I could take a stab at it, I think it's just one line.

@dantio
Copy link
Collaborator

dantio commented Mar 29, 2024

We haven’t experienced this error yet, and I’m not sure how to reproduce it. If you can explain to me how to trigger this error message, I will try to fix it. Please go ahead if you have time to fix it. I would appreciate it. 😊

@nrathi
Copy link
Author

nrathi commented Mar 29, 2024

Here's a repro:

  while (true) {
    try {
        const res = await this.api.trading.GetMyeBaySelling?.(
        {
          SoldList: {
            DurationInDays: 60,
            Include: true,
            OrderStatusFilter: "All",
            Sort: "EndTimeDescending",
          },
        },
        { useIaf: true },
      );
      console.log(res);
      await new Promise((res) => setTimeout(res, 15 * 60 * 1000)); // 15 minutes
    } catch (e) {
      console.log(e);
    }
  }

And eventually, you'll get this error. The token should be refreshed and it isn't:

  error: EbayApiError: Auth token is hard expired.
      at checkEBayResponse (/Users/me/my-app/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/errors/index.js:187:15)
      at XMLRequest.request (/Users/me/my-app/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/XMLRequest.js:118:46)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Traditional.request (/Users/me/my-app/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/index.js:178:20)
      at async Object.GetMyeBaySelling (/Users/me/my-app/node_modules/.pnpm/[email protected]/node_modules/ebay-api/lib/api/traditional/index.js:44:24) {
    description: 'Auth token is hard expired, User needs to generate a new token for this application.',
    meta: {
      Timestamp: '2024-03-29T15:13:35.709Z',
      Ack: 'Failure',
      Errors: [Object],
      Version: 1271,
      Build: 'E1271_CORE_APISELLINGEXTSVC_R1',
      [Symbol(raw-error)]: [Object]
    }
  },

Changing the "catch" as follows works:

  } catch (e) {
    if ( isEBayAuthTokenExpiredError(e)) {
      await eBayApi.OAuth2.refreshToken();
      return myRecursiveFunction(...);
    }
    throw e;
  }
};

function isEBayAuthTokenExpiredError(err: unknown) {
  return (
    err instanceof EBayError &&
    err.description.includes("Auth token is hard expired")
  );
}

@dantio
Copy link
Collaborator

dantio commented Mar 29, 2024

Ah, you are using the Auth token. I see. I'll add this check in the next release. Thank you!

@dantio
Copy link
Collaborator

dantio commented Mar 29, 2024

I have published it as 8.7.2-RC.0.

@nrathi
Copy link
Author

nrathi commented Mar 31, 2024

Thanks! I started using it. Will let you know if there are any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants