Does the latest version of MSAL support loginRedirect() from within an IFrame

Akhil Kondepudi 6 Reputation points
2021-09-06T04:32:24.327+00:00

I have scenario where I have a SPA loading in an IFrame from within another parent page. Currently, I am using loginPopup() from the IFrame for authentication. I wish to migrate to loginRedirect() and am unable to do so due to an authentication error . Please let me know if there is a way to do the same. Thank you!

Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,876 Reputation points Moderator
    2021-09-06T08:53:58.2+00:00

    Hi @Akhil Kondepudi • Thank you for reaching out.

    Assuming you are using MSAL.js, it provides 3 login APIs: loginPopup(), loginRedirect(), and ssoSilent(). To use the redirect flow, you must register a handler for redirect promise. MSAL.js provides handleRedirectPromise() API. When you choose to use the redirect APIs, be aware that you MUST call handleRedirectPromise() to correctly handle the API.

    myMSALObj.handleRedirectPromise()  
        .then((response) => {  
            // your logic  
        })  
        .catch(err => {  
            console.error(err);  
        });  
    
    myMSALObj.loginRedirect(loginRequest);  
    

    Note: It is not recommended to use both interaction types - pop-up and redirect, in a single application.

    Read more:
    https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/initialization.md#choosing-an-interaction-type

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.