Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logoutPopup API to MSAL Browser #2563

Closed
1 of 5 tasks
jonstelly opened this issue Nov 7, 2020 · 14 comments · Fixed by #3044
Closed
1 of 5 tasks

Add logoutPopup API to MSAL Browser #2563

jonstelly opened this issue Nov 7, 2020 · 14 comments · Fixed by #3044
Labels
feature Feature requests. msal-browser Related to msal-browser package

Comments

@jonstelly
Copy link

jonstelly commented Nov 7, 2020

Library

  • msal@1.x.x or @azure/msal@1.x.x
  • @azure/msal-browser@2.x.x
  • @azure/msal-angular@0.x.x
  • @azure/msal-angular@1.x.x
  • @azure/msal-angularjs@1.x.x

Description

The loginPopup() call behaves in a SPA-friendly way, allowing us to stay on our page and authenticate without having to re-load our page. I don't see a way right now to have similar behavior for logout().

The logout() method navigates to https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=...&client-request-id=... and there isn't a way to prevent this, allowing a SPA to stay loaded and simply clear out the MSAL credentials/session.

Is it possible to make a logout call without navigating to login.microsoftonline.com? Or can we get a logoutPopup() added that shows the Microsoft UI prompting for which account to log out inside a popup window instead of the main window?

abacritt/angularx-social-login#306 is an issue where I'm trying to add MSAL authentication to an Angular login library and the MSAL library/provider is the only one that doesn't seem to support a logout without navigating away from the Angular app.

@jonstelly jonstelly added the feature Feature requests. label Nov 7, 2020
@jonstelly jonstelly changed the title logout as ajax instead of navigate? To better align with popup UI behavior logout as popup instead of navigate? To better align with login popup UI behavior Nov 9, 2020
@jasonnutter jasonnutter added the msal-browser Related to msal-browser package label Nov 9, 2020
@jasonnutter
Copy link
Contributor

@jonstelly Thanks for the request, we've heard this request from a few customers, we'll certainly take it under consideration, thanks!

@javila35
Copy link

I'm also interested in this sort of functionality. Glad to see it was brought up recently. Thank you! 🙏🏼

@jasonnutter jasonnutter changed the title logout as popup instead of navigate? To better align with login popup UI behavior Add logoutPopup API to MSAL Browser Dec 2, 2020
@tnorling tnorling linked a pull request Feb 19, 2021 that will close this issue
@fq-selbach
Copy link

This is an absolute must have! Since we work in an Iframe and the logout page cannot be called from within we cannot properly logout atm :-( (or am I missing something here?).

In the meantime would it be possible to get the logout URL and client-request-id somehow to create our own popup via window.open(...)?

@jasonnutter
Copy link
Contributor

See linked PR for proposed design. If you would like this functionality today, you can use the onRedirectNavigate callback to get the url and open the popup yourself. See this sample for an example of how to do that: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/ChromiumExtensionSample/auth.js#L100-L105

@fq-selbach
Copy link

fq-selbach commented Feb 23, 2021

you can use the onRedirectNavigate callback to get the url and open the popup yourself

Oh wait, this is happening BEFORE the logout URL is called? I was assuming this is the redirect AFTER logout. This is actually perfect then 👍
... thinking about it again it actually makes much more sense 😅

@fq-selbach
Copy link

@jasonnutter
It is worth noting that the official example (related tutorial) is using an outdated version of the library by default (2.7.0)!
I had to change the version to latest (2.11.2) AND remove the second CDN since this one was always overwriting my first entry.

Now I actually get the URL :-)

One general comment: The whole structure of the MSAL project is highly confusing. There are dozens of pages with different versions and tutorials for this library and half of them (at least) are outdated and have been replaced later. Maybe someone can clean up a bit before you release v3.0.0 ;-)

@pkanher617
Copy link
Contributor

@fq-selbach Thanks for calling this out. We need to make sure we are updating the sample repos with the latest versions of the release. Glad to hear you were able to resolve your issues!

There are dozens of pages with different versions and tutorials for this library and half of them (at least) are outdated and have been replaced later

Is the tutorial that you linked the only one that is outdated, or are you seeing other areas that need to be updated?

@jasonnutter
Copy link
Contributor

@jasonnutter
It is worth noting that the official example (related tutorial) is using an outdated version of the library by default (2.7.0)!
I had to change the version to latest (2.11.2) AND remove the second CDN since this one was always overwriting my first entry.

Now I actually get the URL :-)

One general comment: The whole structure of the MSAL project is highly confusing. There are dozens of pages with different versions and tutorials for this library and half of them (at least) are outdated and have been replaced later. Maybe someone can clean up a bit before you release v3.0.0 ;-)

Thanks for the feedback, we'll make sure to get those updated. cc @derisen

@fq-selbach
Copy link

Is the tutorial that you linked the only one that is outdated, or are you seeing other areas that need to be updated?

Its hard to say because the very first thing I've tried was based on an outdated YouTube Video (I can't recall the link, but as far as I remember it was on one of Microsofts channels) that used examples of v1 of the library which lead me down a very dark path of failed authentication attempts sometimes mixing v1 and v2 docs 😓. After a few weeks I've tried again and my web-search led me to all kinds of new github.com/AzureAD/, GitHub Wiki, azuread.github.io and Microsoft Docs pages that all had the same topic but different approaches mostly related to all the platform and authentication-flow flavors 🙈 . Sometimes links in the issues would even refer to the "dev" branch of a repository showing new versions of the same stuff ... at some point I just got lost.

Glad to hear you were able to resolve your issues!

I'm able to create my own popup window now using var logoutWin = window.open(url, "_blank", "top=5,left=5,width=480,height=640");
Obviously my original page doesn't know when this window has completed its work. Is there any chance to catch some event related to the logout? The login popup seems to be able to communicate with the original page (how is this working btw??).

Another hint for people trying to use the logout inside an iframe. You need to set the allowRedirectInIframe: true config option as well:

const msalConfig = {
    auth: {
        ...
    },
    cache: {
        ...
    },
    system: {	
        ...
	allowRedirectInIframe: true
    }
}

@jasonnutter
Copy link
Contributor

jasonnutter commented Feb 24, 2021

Obviously my original page doesn't know when this window has completed its work. Is there any chance to catch some event related to the logout? The login popup seems to be able to communicate with the original page (how is this working btw??).

The main window will not know logout has completed until the popup has been redirectd to the post logout redirect uri (assuming that uri is the same domain as the app, which it should be). The linked PR demonstrates how we will do this.

Another hint for people trying to use the logout inside an iframe. You need to set the allowRedirectInIframe: true config option as well:

While this will remove the restriction in MSAL, the logout page itself will not render in the iframe, as AAD sets X-FRAME-OPTIONS to DENY, preventing the logout page from being rendered in an iframe.

@tnorling
Copy link
Collaborator

tnorling commented Mar 2, 2021

All, please see the design proposal for this feature: #3123. We would love to get your feedback even if it's just "looks great". After we've given ample time to review and provide thoughts we'll finalize the linked PR and get this released!

@jonstelly
Copy link
Author

Looks good to me!

I'd also like to say thanks for posting that design proposal for public review before the feature is finished/released. You mention that it's an attempt to improve transparency and improving public visibility into your development process isn't always easy, but I appreciate you guys spending the effort and I'm sure I'm not alone. Thanks.

@fq-selbach
Copy link

While this will remove the restriction in MSAL, the logout page itself will not render in the iframe, as AAD sets X-FRAME-OPTIONS to DENY, preventing the logout page from being rendered in an iframe.

Yes, I just needed it to get the URL and then call logoutWin = window.open(url, "_blank", "top=5,left=5,width=480,height=640") ;-)

All, please see the design proposal for this feature: #3123. We would love to get your feedback even if it's just "looks great". After we've given ample time to review and provide thoughts we'll finalize the linked PR and get this released!

Looks good so far, I was just wondering if the option to submit an account is deprecated? I'd prefer to have a logout where the user doesn't really have to interact with the popup at all, especially since his locally stored credentials will be deleted in any case.

@tnorling
Copy link
Collaborator

tnorling commented Mar 3, 2021

Looks good so far, I was just wondering if the option to submit an account is deprecated? I'd prefer to have a logout where the user doesn't really have to interact with the popup at all, especially since his locally stored credentials will be deleted in any case.

@fq-selbach The account parameter will not be deprecated and will be used the same way it is today. However, if and until changes are made server-side, ending the server session requires interaction regardless of whether you use the existing logout API or the new logoutPopup API. If you don't care about ending the server session and only want local logout you can use the existing logout API and provide the onRedirectNavigate callback and have it return false, which will skip the redirect to the logout endpoint. Please be aware though, that doing this means that the next login attempt will automatically log the user back in without asking for credentials, as the server session is still active.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests. msal-browser Related to msal-browser package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants