AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.67k stars 2.65k forks source link

SharePoint webparts embedding authenticated PowerBi reports combined with URL query parameters #5298

Closed Georg-Trixl closed 2 years ago

Georg-Trixl commented 2 years ago

Core Library

MSAL.js v1 (@azure/msal or msal)

Core Library Version

1.4.17

Wrapper Library

Not Applicable

Wrapper Library Version

-

Public or Confidential Client?

Public

Description

The Customer NGO SOS Chidlren's Villages has the requirement to send to coworkers link-URLs in Emails, with query parameters. Those required query parameters are used to point in the developed single page app to a specific data display, showing data to collaborate on. The app is embedded in SharePoint Webparts and loads openStreetMap data, PNP Search Webparts - Search Results and PowerBi Reports. The PowerBi Reports do require authentication.

I followed samples using package "msal" and PowerBi embedding . The sample leads to UserAgentApplication - getAccount() , after that call every I have is lost due a authentication redirect. I am so far not able to preserve the original URL query parameter nor a react states/variables. (on the other hand if start the app in SharePoint without of any query parameter in the hierarchical data top level and work with it, the PowerBi embedding works very fine.) I do already cut away and memorize the initial URL query parameters in order that the redirection has no problems, when authenticated and returning to application page.

My question is how to get URL query parameters or a React state/variable preserved after a redirect? UserAgentApplication - getAccount() is that a bad way. (Is msal-node msal-react needed in typescript to achieve it?)

MSAL Configuration

scopes: string[] = ["https://analysis.windows.net/powerbi/api/Report.Read.All"];

Relevant Code Snippets

import { UserAgentApplication, AuthError, AuthResponse } from "msal";
---------------
    const msalInstance: UserAgentApplication = new UserAgentApplication( msalConfig );
---------------

    if ( msalInstance.getAccount()) {
      msalInstance
        .acquireTokenSilent(loginRequest)
        .then((response: AuthResponse) => {

Identity Provider

Azure AD / MSA

Source

External (Customer)

tnorling commented 2 years ago

@Georg-Trixl I'm a little confused, the getAccount API does not invoke a redirect. Are you perhaps calling loginRedirect or acquireTokenRedirect somewhere? If so, you can preserve the query parameters through the redirect by providing them to the state parameter which will be returned to you in the AuthenticationResult object upon returning from the redirect and calling handleRedirectCallback

ghost commented 2 years ago

@Georg-Trixl This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

Georg-Trixl commented 2 years ago

So i figured it out on my own, in SPFX the state and extraQueryParameters are also not usefull. The in SPFX, PNPJS and also MSAL-React integrated authentication, things are not helping to embed a PowerBI-Report into a SharePoint - when a developer is required to put PowerBI into a SharePoint Webpart without of an pre generated embedding Link.