Angular MSAL Logout Redirecting not working, Login event triggering after logout

Savitha G Nair 0 Reputation points
2024-01-18T09:05:29.88+00:00
here is my code 
port const msalConfig: Configuration = {
    auth: {
        clientId: '',
        authority: b2cPolicies.authorities.signUpSignIn.authority,
        knownAuthorities: [b2cPolicies.authorityDomain],
        redirectUri: 'http://localhost:4200',
        postLogoutRedirectUri: 'http://localhost:4200',
        scopes: 
        
    },
    cache: {
        cacheLocation: BrowserCacheLocation.LocalStorage,
        storeAuthStateInCookie: false, // set to true for IE 11. Remove this line to use Angular Universal
        secureCookies: false,
      },
    system: {
        loggerOptions: {
            loggerCallback(logLevel: LogLevel, message: string) {
            },
            logLevel: LogLevel.Verbose,
            piiLoggingEnabled: false
        }
    }

logout() {
 localStorage.clear();
    console.log('logout executed');
    debugger;
    if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
      this.msalService.logoutPopup({
        account: this.authService.instance.getActiveAccount(),
      });
    } else {
      console.log('logout else executed');
      // Use MSAL service's logout method directly
      this.msalService.logoutRedirect();
    }
  } after logout its not redirecting to microsoft login page and 

appcomponent.ts

this.msalBroadcastService.msalSubject$
      .pipe(
        filter(
          (msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS
        ),
        takeUntil(this._destroying$)
      )
      .subscribe((result: EventMessage) => { this part of code executing after logout.
  
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Entra | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2024-01-22T07:00:29.5866667+00:00

    Hi @Savitha G Nair ,

    Thanks for reaching out.

    It seems like you are having trouble with the logout functionality in your Angular application that uses MSAL.

    MSAL.js provides a logout method in v1, and introduced logoutRedirect method in v2 that clears the cache in browser storage and redirects the window to the Microsoft Entra sign-out page. After sign-out, by default Microsoft Entra ID redirects back to the page that invoked logout.

    If you are trying to sign out in Azure AD B2C from Social Idp, the this is expected behavior. The sign-out clears the user's single sign-on state with Azure AD B2C, but it might not sign the user out of their social identity provider session.

    Reference- https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/working-with-b2c.md#b2c-and-sign-out-experience


Your answer

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