Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Error acquiring a token in a React app that signs in with Azure

ErrorToken acquisition in iframe failed due to timeout.

Short answer

Read the MSAL error code first; it names the cause. In React apps four codes cover most cases: a redirect page whose router strips the hash (monitor_window_timeout), overlapping interactive calls (interaction_in_progress), calling APIs before initialize finishes, and an MSAL-protected redirect page inside the silent iframe (block_iframe_reload).

  • Applies to MSAL Browser (msal-browser), MSAL React (msal-react), React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Catch the error from acquireTokenSilent and print its errorCode. The code decides which cause below applies.

    try {
      await instance.acquireTokenSilent({ scopes: ['User.Read'], account });
    } catch (e) {
      console.log(e.errorCode, e.errorMessage);
    }
  2. 2Match what you see, then jump to its fix

    1. 1monitor_window_timeout, hash_empty_error or hash_does_not_contain_known_propertiesThe redirect page's router removes or changes the hashFix
    2. 2interaction_in_progressTwo interactive calls overlapFix
    3. 3uninitialized_public_client_applicationAn API is called before initialize has finishedFix
    4. 4block_iframe_reloadThe redirect page runs MSAL inside the hidden iframeFix

What does the error look like?

  • Token acquisition in iframe failed due to timeout.
  • Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API.
  • You must call and await the initialize function before attempting to call any other MSAL API.
  • Request was blocked inside an iframe because MSAL detected an authentication response.

Cause 1 of 4

The redirect page's router removes or changes the hash

1Check

Silent calls open a hidden iframe that returns to your redirectUri with the response in the URL hash. If your router strips the hash or navigates away first, MSAL never reads it and times out.

grep -rn "redirectUri" src/

2Fix

Use a blank page as the redirectUri for silent and popup calls, register it on the app registration, and pass it in the request.

instance.acquireTokenSilent({
  scopes: ['User.Read'],
  account,
  redirectUri: 'http://localhost:3000/blank.html',
});

3Verify

Run the call again; it resolves with a token and no timeout error.

npm run dev

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

Two interactive calls overlap

1Check

loginPopup, loginRedirect, acquireTokenPopup and acquireTokenRedirect are async. Starting one while another is unresolved, or before handleRedirectPromise has completed, throws.

grep -rn "acquireTokenPopup\|acquireTokenRedirect\|loginRedirect\|loginPopup" src/

2Fix

Await each interactive call, await handleRedirectPromise before calling a redirect API, and use the inProgress value from useMsal to start an interaction only when it is none.

const { instance, inProgress } = useMsal();
if (inProgress === InteractionStatus.None) {
  await instance.acquireTokenPopup(request);
}

3Verify

Reload the page; the error no longer appears, including in a new tab.

npm run dev

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

An API is called before initialize has finished

1Check

login, acquireToken and handleRedirectPromise need initialize to have completed first.

grep -rn "new PublicClientApplication" -A 6 src/

2Fix

Call and await initialize before any other MSAL API.

const msalInstance = new PublicClientApplication(msalConfig);
await msalInstance.initialize();
await msalInstance.handleRedirectPromise();

3Verify

The first token request after load succeeds.

npm run dev

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 4

The redirect page runs MSAL inside the hidden iframe

1Check

If the page used as redirectUri also calls login or acquireToken (for example through MsalAuthenticationTemplate or useMsalAuthentication), MSAL blocks it inside the silent iframe.

grep -rn "useMsalAuthentication\|MsalAuthenticationTemplate" src/

2Fix

Point silent requests at a blank redirectUri, or make sure the redirect page does not render MSAL-protected components.

instance.acquireTokenSilent({
  scopes: ['User.Read'],
  redirectUri: 'http://localhost:3000/blank.html',
});

3Verify

Silent acquisition completes without the iframe error.

npm run dev

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Use a dedicated blank redirect page for silent and popup flows.
  • Always pass the account to acquireTokenSilent, and call it each time you need an access token.
  • Keep all MSAL calls under MsalProvider and await initialize at startup.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.