Share via

How to get Silent SSO to Work on Browser closes in MSAL with Azure

Ahmad Mujeeb 10 Reputation points
2026-02-22T00:45:38.4833333+00:00

In my implementation, I'm using silent SSO which works perfectly when opening a new tab — ssoSilent successfully retrieves the existing session without any issues. The problem occurs when the browser is closed entirely and reopened, where it errors out and falls back to a full login.

I noticed that when the 'Stay signed in?' prompt appears during login and the user selects Yes, ssoSilent is able to recover the previous session even after a full browser close. The goal is to ensure the user remains authenticated after closing and reopening the browser, regardless of whether the 'Stay signed in?' prompt is shown. I just need help on accomplishing this and down below is my code

const response = await this.msalService.instance.handleRedirectPromise();
    
    if(response!== null && response.account !== null) {
        this.msalService.instance.setActiveAccount(response.account);
        return
    }


    const accounts = this.msalService.instance.getAllAccounts();
    
    if(accounts.length > 0) {
      this.msalService.instance.setActiveAccount(accounts[0]);
    }


    const silentRequest = {
      scopes: ["User.Read"],
    }


    const result = this.msalService.ssoSilent(silentRequest).subscribe({
      next: (result) => {
        console.log("acquireTokenSilent response:", result);
      },
      error: (error) => {
        console.error("acquireTokenSilent error:", error);
        this.loginRedirect({})
      }
    }) 

Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-22T00:45:53.2333333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To ensure that Silent SSO works even after the browser is completely closed and reopened, you need to consider a few key factors regarding session persistence and cookie management. Here are some suggestions based on your implementation and the context provided:

    1. User Session Management: Ensure that the session is maintained properly by utilizing the ssoSilent method effectively. If the user selects "Stay signed in?" during the login process, it allows the session to persist across browser sessions. However, if this prompt is not shown, the session may not be retained depending on the browser's cookie settings.
    2. Third-party Cookies: Be aware that ssoSilent attempts to open a hidden iframe to reuse an existing session with Microsoft Entra ID. This will not work in browsers that block third-party cookies (like Safari), which can lead to errors when trying to silently sign in after a browser restart. You may want to check the browser settings or provide guidance to users about enabling third-party cookies.
    3. Redirect URI: For better performance and to avoid issues, set the redirectUri to a blank page or another page that does not use MSAL. This can help in managing the session more effectively.
    4. Error Handling: In your code, you are already handling errors by falling back to a full login. This is a good practice. Ensure that you log the specific error messages to understand if the issue is related to session persistence or other factors.
    5. Interactive Sign-in: If ssoSilent fails, you may need to prompt the user to log in interactively. This can be done using loginPopup() or loginRedirect(), especially if the session cannot be recovered silently.

    Here's a brief example of how you might modify your error handling:

    const result = this.msalService.ssoSilent(silentRequest).subscribe({
      next: (result) => {
        console.log("acquireTokenSilent response:", result);
      },
      error: (error) => {
        console.error("acquireTokenSilent error:", error);
        // Check if the error is due to session issues and prompt for login
        if (error instanceof InteractionRequiredAuthError) {
          this.loginRedirect({});
        }
      }
    });
    

    By ensuring that the session management is robust and considering browser-specific behaviors regarding cookies, you can improve the chances of maintaining a silent session even after a complete browser restart.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.