Microsoft-authentication-library-for-js: Issue with loginPopup and when redirectUrl is not exactly the same as the registered redirect Url

Created on 15 Nov 2017  路  6Comments  路  Source: AzureAD/microsoft-authentication-library-for-js

I'm having an MSAL based JavaScript application that can be hosted on any sub-page of the domain, and I use the loginPopup method to retrieve the tokens. This works fine if the exact url of the page is used as redirectUri and the same page (for instance https://foo.contoso.com/pages/bar.aspx) is registered in the app registration portal. However I'd like to have my redirectUri be the set to https://foo.contoso.com and have that url to be registered as the reply url.

The current behavior is that I'm able to log in using the popup and then it just loads the "top" page, not closing the popup window and not retrieving the id_token. The only thing that happens is that MSAL logs that the windows is closing.

Thoughts?

Most helpful comment

@wictorwilen : you need to have the msal object instanciated in the page pointed to by the redirectUri, so that this object closes the popup.

All 6 comments

@wictorwilen : you need to have the msal object instanciated in the page pointed to by the redirectUri, so that this object closes the popup.

Hi @jmprieur. I have also the same exact scenario working with SharePoint and I'm not sure to understand what I am supposed to to in this case using MSAL.

For now, when I use the loginPopupmethod, I am able to sign-in but the popup does not close and actually redirects inside the popup itself (similar to this issue The redirectUriconfigured in my component and from my AD app are the same. The only difference is the caller URL has query parameters at the time of the call. What I'am missing?

How I can get the implicit flow work initiated in a React component from every pages in my SharePoint site? I don't know what to put in the redirect URL in my AD app and inside the component in this scenario.

I previously used ADAL.js and it worked as expected. Can you point me to the right direction?

Thanks!

Nevermind, I found the solution by using an SPFx extension present on every page so the login popup is now able to close. In the redirect URL (SPFx/AAD), I've just specified the root site collection URL.

@FranckyC you saved my day. Redirect URL must have UserAgentApplication initialized.

Closing the issue as it is solved in the answers above. Thank you @FranckyC @pgarriga

What does it mean - Redirect URL must have UserAgentApplication initialized ? Do i need to create a new User agent application on redirect url like Msal.UserAgentApplication(client id, null, null); ?

Was this page helpful?
0 / 5 - 0 ratings