react-aad icon indicating copy to clipboard operation
react-aad copied to clipboard

Page refreshes on every access token acquisition

Open canmenekse opened this issue 5 years ago • 0 comments
trafficstars

Library versions

  • react-aad-msal: 2.3.5
  • msal: 1.2.0

Describe the bug I am seeing the page gets reloaded every time I get an access token. Here is what I am doing:

in the App.tsx

export const DisplayTokens: React.FC = () => {
  const [forceUpdateVal, setForceUpdateVal] = React.useState(0);

  const arr = Object.keys(acquiredTokens).map(key => {
    return (
      <li key={key}>
        {key}: {acquiredTokens[key]}{' '}
      </li>
    );
  });
  return (
    <div>
      Force Update is {forceUpdateVal}
      <ul>{arr}</ul>
      <button onClick={() => setForceUpdateVal(forceUpdateVal + 1)}>Update</button>
    </div>
  );
};

export const App: React.FC = () => {
  if (window.self !== window.top) {
    return null;
  }
  return (
    <Provider store={store}>
      <AzureAD forceLogin={true} provider={authProvider} reduxStore={store}>
        <div>
          <DisplayTokens />
          <button onClick={() => authProvider.logout()}>Logout</button>
        </div>
      </AzureAD>
    </Provider>
  );
};

then upon success in a redux saga:


yield all([call(loadX), call(loadY)]);

where loadX and loadY needs different tokens

and in these calls I acquire the token with

const token = await authProvider.getAccessToken({ scopes });

basically what I observe is

  1. When logged in, gets the token for LoadX
  2. Redirects and the page gets refreshed (Have token for X)
  3. go and gets the token for LoadY
  4. Redirects and the page gets refreshed again (Have token for X and Y)

and If I have 7 different scopes for example I get 7 page refreshes.

To Reproduce I ideally wanted to have a good repro however even repro steps are bit confusing. So any insight would help.

The issue very rarely happens in the browsers I use frequently, but when I installed a new browser(Brave - chromium based). I can repro it consistently by logging-out and login back in. If I go Incognito in the browsers I use frequently, I do not face the same issue, it works fine It might be single sign-on related thing too apologies for the vagueness of the description.

Any help/hint is appreciated, thank you

Desktop (please complete the following information):

  • OS: Windows

canmenekse avatar May 13 '20 18:05 canmenekse