Is there a way to know when an msal redirect is in progress?


Im using the @azure/msal-browser and @azure/msal-angular packages in order to simply retrieve an MSAL token for my signed in users. Since all I really need is the token I have only provided the MsalService and MSAL_INSTANCE in my app.module.ts. I am using the redirect flow and have chosen to subscribe to the .handleRedirectObservable() method myself instead of using the MsalRedirectComponent (so that I know exactly when the token is available).

My problem is that when the redirect happens and i am forwarded back to my application there is a period of time where my app is running but the redirect interaction still hasnt quite finished. If I allow for my app to actually start running at this point there is a chance that It will try to use the token before it is truly there and cause errors. So instead I am having to define a method called isInteractionInProgress and call that in my app.component.ts before actually starting execution of my app:

  public isInteractionInProgress(): boolean {
    for (let i = 0; i < sessionStorage.length; i+= 1) {
      if (sessionStorage.getItem(sessionStorage.key(i)) === 'interaction_in_progress') {
        return true;
    return false;

Since I dont know a reliable way to generate the key that the msal-angular library uses to store the ‘interaction_in_progress’ value im having to iterate through the session storage myself and look for this key. If it exists then my app knows an MSAL token is on the way and it needs to wait.

Is there a better solution for this? It almost seems like this is supposed to be doing what I need:

        filter((status: InteractionStatus) => status === InteractionStatus.None),
      .subscribe(() => {
        // Do user account/UI functions here

But all it does is activate on ‘none’ twice and the second ‘none’ seems to be when the token is actually available but im not sure if that is true.

So is there a reliable way to know when the redirect is actually happening? Thanks!

Source: Angular Questions

Categorized as angular, azure, msal, msal-angular, redirect Tagged , , , ,


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us