question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refreshAuthLogic is not recalled on a second failure

See original GitHub issue

Assume that you are making a request which returns a 401.

refreshAuthLogic will be called as it should and this second request is returning again a 401. This second failure is not triggering refreshAuthLogic again, is this intentional?

Is there any way to re-trigger the callback?

My scenario goes as follows: A web application is utilizing the UMA flow which uses RPT Tokens to access resources. RPT tokens are cached and they may expire. On expiration a 401 is issued and I retry using a normal access token which will respond (again) with a 401 and a permission ticket which in turn will be exchanged for a new RPT token. So the scenario is request -> 401 -> request again -> 401 -> request again -> possibly 200

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
fullergalwaycommented, Apr 30, 2021

I had the same problem, and solution provided by @CteixeiraPW seems to work; In my code I made this change.

Before

 createAuthRefreshInterceptor(api.axiosInstance, refreshAuthLogic(api));

After

  createAuthRefreshInterceptor(api.axiosInstance, refreshAuthLogic(api), {
    pauseInstanceWhileRefreshing: true,
  });

  api.axiosInstance.interceptors.response.use(
    (response) => response,
    async (error) => {
      const request = error.config;
      if (request.skipAuthRefresh) return error;

      if (
        error &&
        error.response &&
        error.response.status === 401 &&
        error.response.headers['www-authenticate'] === 'Bearer'
      ) {
        // let's retry
        return api.axiosInstance(request);
      }

      throw error;
    }
  );

4reactions
israelKusayevcommented, Oct 31, 2020

I think it was because I set pauseInstanceWhileRefreshing to true but if I remove it, the second request is sent with the old token

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

@blueberry6401/axios-auth-refresh - npm
All the new requests created while the refreshAuthLogic has been processing will be bound onto the Promise returned from the refreshAuthLogic ...
Read more >
Trying to get axios-auth-refresh working with NodeJS
As far as I can tell, the refreshAuthLogic function is working properly (because it returns a new auth token), but everything stops after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found