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:
- 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)
- Make sure all your workspaces are new workspaces.
- 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.