Bypass the account selection screen while sign out(log out) @azure/msal-angular V2
Asked Answered
M

2

7

I am using the @azure/msal-angular version 2 and Angular version 13. The scenario is when the user signed in to the application need to authorize the user if he doesn't have access need to sign out the user from the application. which will be happened in background by calling msalService.logoutRedirect(). While calling the logout function the microsoft account selection screen is displayed to signout instead of auto signout. Is there any way to skip the account selection screen to siignout.

Mhd answered 4/3, 2022 at 12:28 Comment(4)
I think this is expected behavior github.com/AzureAD/microsoft-authentication-library-for-js/blob/… see more about this here.Wallpaper
Hi @Wallpaper Thanks for the quick reply. Is there any way to bypass it?Mhd
If you click on above doc link, then you can find link of Configuration options, May be there you can find out more options, But I am not sure about it.Wallpaper
Same happening in @azure/msal-angular V3X Any pointers ?Bodleian
A
10

To do this, first you have to setup the login_hint optional claim in the ID token. That needs to be done on the app registration side of things. (Azure Portal -> App Registration -> Token Configuration -> Add Optional Claim -> ID -> login_hint)

Once that claim is in place, MSAL will pass that into logoutRedirect() and will skip the account picker prompt.

const account = this.msalService.instance.getActiveAccount();
this.msalService.logoutRedirect({ account: account });

Ref: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/logout.md#promptless-logout

Anticholinergic answered 13/7, 2022 at 18:21 Comment(1)
Do you know why this is a must have claim for automatic logout? I mean in the end there is a setActiveAccount that can be used to specify the account to redirect. Why also a custom claim? (BTW thanks it worked for me)Scapegrace
A
0

As mentioned here in the documentation: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/logout.md#skipping-the-server-sign-out You may logout from your application without affecting their login status in other applications

msalInstance.logoutRedirect({
    onRedirectNavigate: (url) => {
        // Return false if you would like to stop navigation after local logout
        return false;
    }
});
Arran answered 22/4 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.