1

I've been searching for a while about the integration of PowerBI with C# WinForms and it seems a little confusing to me. It seems there are a few documents with the whole process but I just want to view the PowerBI Dashboard from a C# WinForms App.

I gathered this info: - https://www.nuget.org/profiles/powerbi || https://github.com/microsoft/PowerBI-CSharp || Is it possible to embed power bi into desktop application? (It seems outdated)

The desired output was opening an external PowerBI Link from a Windows Application and authenticate according to the user (logged from the native app).

Maybe I could use the Server Principal for authentication but I need to know how to do this.

realmayus
  • 13
  • 4
Sérgio Rebelo
  • 91
  • 1
  • 11

1 Answers1

1

You can check the example for embedding in WPF application. As far as I remember, the only difference in the C# code is that WPF's method WebBrowser.InvokeScript in WinForms should be changed to WebBrowser.Document.InvokeScript.

About authentication, this example will prompt for credentials. If this isn't desired, you can use UserPasswordCredential like this:

var uc = new UserPasswordCredential("user@example.com", "MyStrongP@ssw0rd");
authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, uc);

Authenticating with service principal is explained in this blog post, but in essence you should follow these steps:

  1. Create and provision a service principal as described above in this blog post, or follow the steps in the documentation. (i.e. register a server-side web application in AAD to use with Power BI, enable the toggle in the Admin portal, apply it for specific security groups, add the AAD web application created to one of those security groups)
  2. Make sure all your workspaces are new workspaces.
  3. Add the service principal as an admin of the new workspaces. This can be done through the API in two ways:
    • The service principal creates a new workspace through API. Please note that service principal cannot login to Power BI Portal.
    • A workspace admin adds the service principal as an admin. To add a service principal to a workspace or to perform any other operation on a service principal, you need the service principal object ID.
Andrey Nikolov
  • 12,967
  • 3
  • 20
  • 32