Solvedmicrosoft authentication library for js User cannot log out
✔️Accepted Answer
For anyone who is stumped on this and finds this thread, I found a solution.
Similar to how you have to explicitly set your clientApplication authority before you redirect to login
this.clientApplication.authority = https://${msalTenant}.b2clogin.com/${msalTenant}.onmicrosoft.com/${msalSignInPolicy}; this.clientApplication.loginRedirect();
You have to explicitly set this before triggering logout, otherwise you are directed to the common MS online logout page.
this.clientApplication.authority = https://${msalTenant}.b2clogin.com/${msalTenant}.onmicrosoft.com/${msalSignInPolicy}; this.clientApplication.logout();
I figured this out by examining the network call to openid-configuration
when the login process is triggered. This comes back with an object that has the property end_session_endpoint
which matches the URL pattern above.
In the source code for logout it looks for an end session endpoint and if it doesnt exist, redirects you to common login online for logout. Where your redirect URI is not configured and it breaks.
tldr;
Set the client application authority before logging out.
Set the logout redirect uri as a reply URL in your azure B2C application configuration.
Other Answers:
I published the recorded steps so you can see:
I'm submitting a...
Browser:
Library version
Library version: 1.0.1
Current behavior
Sometimes, AD stops at this page and asks the user to select which account they should log out of. Other times, it blows right past it and automatically redirects to the next page.
Notice the
post_logout_redirect_uri
WAS in the first page, but is now gone. MSAL seems to be doing its part, but something gets lost during this redirect on the identity provider.The page stays there with the message "You signed out of your account. It's a good idea to close all browser windows". The user has no way to return to the app.
Manually browse back to the app.
User does not appear to be logged in. A request is sent to:
Which returns with the following from the hidden iFrame injected by MSAL:
"Loading frame has timed out after: 6 seconds for scope profile openid offline_acces"
And the following from a manual call to MSAL acquireTokenSilent():
"Token renewal operation failed due to timeout."
This is okay. I'd expect these to fail.
User is NOT promped for credentials. They are authenticated and automatically redirected back to the app.
Expected behavior
Other