AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.64k stars 2.65k forks source link

@azure/msal-angular ACCOUNT_ADDED and ACCOUNT_REMOVED events are not getting triggered #6958

Open ajhaver opened 7 months ago

ajhaver commented 7 months ago

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.1.0

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

3.0.4

Public or Confidential Client?

Public

Description

Hi ,

My usecase is when multiple tabs are open then if in one tab we trigger logout, it should be logged out from all the windows and tabs.

I am capturing the events as disclosed in documents. But, my events are not being trigerred.

Error Message

No response

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

MSAL Configuration

auth: {
    clientId: environment.adb2cConfig.clientId,
    authority:`${environment.adb2cConfig.authority}/${environment.adb2cConfig.authorityDomain}/${environment.adb2cConfig.signUpSignIn}`,
    knownAuthorities: [ environment.adb2cConfig.authority],
    redirectUri: environment.adb2cConfig.redirectUri,
    postLogoutRedirectUri: environment.adb2cConfig.postLogoutRedirectUri,
    navigateToLoginRequestUrl: false,.
  },
  cache: {
    cacheLocation: BrowserCacheLocation.LocalStorage, // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
    storeAuthStateInCookie: isIE, // Set this to "true" if you are having issues on IE11 or Edge
  }
  }

Relevant Code Snippets

this.authService.instance.enableAccountStorageEvents();
this.activeAccount = this.authService.instance.getActiveAccount();

this.msalBroadcastService.msalSubject$
            .pipe(
                filter((msg: EventMessage) => msg.eventType === EventType.ACCOUNT_ADDED || msg.eventType === EventType.ACCOUNT_REMOVED),
            )
            .subscribe((result: EventMessage) => {
                if (this.authService.instance.getAllAccounts().length === 0) {
                    window.location.pathname = "/";
                } else {
                    this.setLoginDisplay();
                }
            });

Reproduction Steps

Any configuration must be checked ? In order to trigger the event ?

Expected Behavior

Events should be triggered.

Identity Provider

Azure B2C Custom Policy

Browsers Affected (Select all that apply)

Chrome

Regression

no

Source

External (Customer)

ajhaver commented 6 months ago

Still waiting for responses.

@hectormmg can you help on the above ? @tnorling

Trying to logout from all the tabs, event is not being captured. (ACCOUNT_ADDED AND ACCOUNT_REMOVED)