MSAL v2 Angular - Logout Issue

310 views Asked by At

I am using the @azure/msal-angular version 2 and Angular version 13. The scenario is while calling the logout function the microsoft account signing out the app ( APP A ) successfully. But Ideally other than this app ( APP A ), no other apps which are login already ( Using Microsoft ), should not log out.

( Apps like Microsoft Teams, Outlook, etc... ) These apps are I opened in same browser.

Below code for logout.

let accountId  = this.authService.instance.getAllAccounts()[0]?.homeAccountId;

const accountInfoActiveAcc = this.authService.instance.getAccountByHomeId(accountId);

this.authService.logoutPopup({ account: accountInfoActiveAcc });

Please help me to resolve this issue. Thanks in advance.

1

There are 1 answers

2
SaiVamshiKrishna On BEST ANSWER

In the scenario you described, you want to log out from the current app without logging out other apps. To do this, you should set the mainWindowRedirectUri parameter to the redirect URI of your app. This will ensure that your app remains logged in, even though the user has logged out from their Microsoft account.

Here is an example of how to log out from the current app without logging out other apps:

In my component.ts updated logout as below

logout() {
if (this.msalGuardConfig.interactionType  ===  InteractionType.Popup) {
this.authService.logoutPopup({
mainWindowRedirectUri:  "/"
});
} else {
this.authService.logoutRedirect({
mainWindowRedirectUri:  "/",
});
} 
}

Result I opened my Application with Credentials in Localhost enter image description here

enter image description here

enter image description here

enter image description here

After Logout im able to stay logged other Apps

enter image description here