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.

MSAL Angular w/ B2C SPA client code flow w/ pkce

See original GitHub issue

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.21.0

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

2.1.0

Description

When the refresh token expires, with an angular spa configured for code flow pkce w/ b2c, the application goes into an infinite loop and becomes unresponsive after 24 hours when the refresh token expires

Error Message

Got 1000’s and 1000’s of these logs in console, to the point that the browser becomes unusable

Error: Uncaught (in promise): BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. For more visit: aka.ms/msaljs/browser-errors. t@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869928 t@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3887338 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3889032 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8135249 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8152234 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869378 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868420 A@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:104040 CC@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868179 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8175348 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869378 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868420 A@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:104040 CC@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868179 acquireTokenRedirect@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3971415 acquireTokenInteractively@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3979547 error@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3899629 onInvoke@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3568317 run@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:92043 @https://www.example.org/polyfills.1652abd69e0565092c78.js:1:102978 onInvokeTask@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3568210 runTask@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:92662 v@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:99244 promiseReactionJob@[native code] ua (main.bbbbe4bab3b701f34f01.js:1:3491864) handleError (main.bbbbe4bab3b701f34f01.js:1:3492035) next (main.bbbbe4bab3b701f34f01.js:1:3574419) (anonymous function) (main.bbbbe4bab3b701f34f01.js:1:3558595) __tryOrUnsub (main.bbbbe4bab3b701f34f01.js:1:3454720) next (main.bbbbe4bab3b701f34f01.js:1:3453973) _next (main.bbbbe4bab3b701f34f01.js:1:3453160) next (main.bbbbe4bab3b701f34f01.js:1:3452935) next (main.bbbbe4bab3b701f34f01.js:1:3457595) emit (main.bbbbe4bab3b701f34f01.js:1:3558466) run (polyfills.1652abd69e0565092c78.js:1:92044) onHandleError (main.bbbbe4bab3b701f34f01.js:1:3568589) runGuarded (polyfills.1652abd69e0565092c78.js:1:92224) (anonymous function) (polyfills.1652abd69e0565092c78.js:1:100874) v (polyfills.1652abd69e0565092c78.js:1:99312) promiseReactionJob

Msal Logs

Error: Uncaught (in promise): BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. For more visit: aka.ms/msaljs/browser-errors. t@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869928 t@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3887338 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3889032 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8135249 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8152234 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869378 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868420 A@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:104040 CC@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868179 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:8175348 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3869378 @https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868420 A@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:104040 CC@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3868179 acquireTokenRedirect@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3971415 acquireTokenInteractively@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3979547 error@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3899629 onInvoke@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3568317 run@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:92043 @https://www.example.org/polyfills.1652abd69e0565092c78.js:1:102978 onInvokeTask@https://www.example.org/main.bbbbe4bab3b701f34f01.js:1:3568210 runTask@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:92662 v@https://www.example.org/polyfills.1652abd69e0565092c78.js:1:99244 promiseReactionJob@[native code] ua (main.bbbbe4bab3b701f34f01.js:1:3491864) handleError (main.bbbbe4bab3b701f34f01.js:1:3492035) next (main.bbbbe4bab3b701f34f01.js:1:3574419) (anonymous function) (main.bbbbe4bab3b701f34f01.js:1:3558595) __tryOrUnsub (main.bbbbe4bab3b701f34f01.js:1:3454720) next (main.bbbbe4bab3b701f34f01.js:1:3453973) _next (main.bbbbe4bab3b701f34f01.js:1:3453160) next (main.bbbbe4bab3b701f34f01.js:1:3452935) next (main.bbbbe4bab3b701f34f01.js:1:3457595) emit (main.bbbbe4bab3b701f34f01.js:1:3558466) run (polyfills.1652abd69e0565092c78.js:1:92044) onHandleError (main.bbbbe4bab3b701f34f01.js:1:3568589) runGuarded (polyfills.1652abd69e0565092c78.js:1:92224) (anonymous function) (polyfills.1652abd69e0565092c78.js:1:100874) v (polyfills.1652abd69e0565092c78.js:1:99312) promiseReactionJob

MSAL Configuration

{
      auth: {
        clientId: this.config.b2cConfiguration.b2cPolicies.clientId,
        authority:
          this.config.b2cConfiguration.b2cPolicies.authorities.signUpSignIn
            .authority,
        redirectUri: this.config.b2cConfiguration.b2cPolicies.redirectUri,
        postLogoutRedirectUri:
          this.config.b2cConfiguration.b2cPolicies.postLogoutRedirectUri,
        knownAuthorities: [
          this.config.b2cConfiguration.b2cPolicies.authorityDomain,
        ],
      },
      cache: {
        cacheLocation: BrowserCacheLocation.LocalStorage,
        storeAuthStateInCookie: this.isIE, // set to true for IE 11
      },
    }

Relevant Code Snippets

N/A, normal use of MSAL

Reproduction Steps

  1. Log into angular application
  2. Leave on for 24 hours (allowing silent refresh to occur).
  3. After 24 hours when the refresh token expires, B2C will throw a 400 error and MSAL goes into an infinite loop with the following error in the logs (after 15 minutes, I literally got 1000’s of pages of the same error in console)

Expected Behavior

After refresh token expires, it should redirect to B2C, get a fresh set of token/refresh token and start the cycle new

Identity Provider

Azure B2C Custom Policy

Browsers Affected (Select all that apply)

Safari

Regression

No response

Source

External (Customer)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
johnyoungnvscommented, Mar 14, 2022

No updates yet, still getting an infinite loop when msal tries to do refresh token cycle w/ b2c

we’re adding some logic to clear the local/session storage after 12 hours so we don’t hit the 24 hour refresh token expiry time now to avoid the issue from happening, but it is just a bandaid fix so users aren’t stuck

we think the problem starts from this

https://{{B2C_TENANT}}.b2clogin.com/{{B2C_TENANT}}.onmicrosoft.com/b2c_1a_signuporsignin/v2.0/.well-known/openid-configuration due to access control checks.

we tried this on both a setup with frontdoor and without front door, and it gives the same issue, cause after this, it goes into its infinite loop

0reactions
msftbot[bot]commented, May 8, 2022

@johnyoungnvs This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSAL Angular auth code flow - Microsoft Q&A
This version of the library uses the OAuth 2.0 Authorization Code Flow with PKCE. First you need to register the angular application MSAL....
Read more >
How to implement Authorization Code Grant with PKCE in ...
js 2.x (msal-browser) implements auth code (w/ PKCE) flow. There is no reason for you not to use it with your Angular project ......
Read more >
microsoft-authentication-library-for-js/README.md at dev
The MSAL library for JavaScript enables client-side JavaScript ... This version of the library uses the OAuth 2.0 Authorization Code Flow with PKCE....
Read more >
Using the Authorization Code Flow with PKCE in Azure AD ...
This authorization code flow was recently enabled in Microsoft Azure AD. More information can be found here. Microsoft also released an update ...
Read more >
angular msal refresh token | The AI Search Engine You Control
With MSAL.js 2.0 you can use the authorization flow with PKCE and refresh tokens in the Microsoft ... Angular w/ B2C SPA client...
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