Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Creating an embedded report with a fabric datasource using service principle authentication

I have an app that displays power bi reports from a workspace.

When I use fabric as a datasource, I get an error in 

 

 

var tokenResponse =
                await client.Reports.GenerateTokenAsync(
                    new Guid(SelectedWorkspaceId),
                    new Guid(SelectedReportId),
                    generateTokenRequestParameters);

 

 

 

Founder_0-1712214254149.png

 

I can get an fabric access token using a service principle, but this doesn't work when passed to Show report

 

 

 

  string[] scopes = new string[] { "https://api.fabric.microsoft.com/.default" };

  ConfidentialClientApplicationBuilder confidentialClientAppBuilder =
      ConfidentialClientApplicationBuilder.Create(ClientId)
      .WithClientSecret(ClientSecret)
      .WithAuthority(Authority)
      .WithTenantId(tenantId);

  IConfidentialClientApplication confidentialClientApplication = confidentialClientAppBuilder.Build();

  AuthenticationResult result = await confidentialClientApplication.AcquireTokenForClient(scopes)
      .ExecuteAsync()
      .ConfigureAwait(false);

  
  return result.AccessToken;

 

 

 

3 REPLIES 3
Anonymous
Not applicable

HI @Anonymous,

It seems like you faced the 400 error, this error occurs when a request sent to a website server is incorrect or corrupt, and the server receiving the request can’t understand it.

rest - 400 BAD request HTTP error code meaning? - Stack Overflow

AFAIK, the root URL of rest API should be https://api.powerbi.com/v1.0/myorg. According to your descriptions, it seems like you modify it to https://api.fabric.microsoft.com/ and it did not able to be responded with these requests.

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

 

 using (var client = new PowerBIClient(
     new Uri("https://api.powerbi.com/"), tokenCredentials))
 {
     var report =
     await client.Reports.GetReportInGroupAsync(
         new Guid(SelectedWorkspaceId),
         new Guid(SelectedReportId));

     var generateTokenRequestParameters =
         new GenerateTokenRequest(accessLevel: TokenAccessLevel.View);

     var tokenResponse =
         await client.Reports.GenerateTokenAsync(
             new Guid(SelectedWorkspaceId),
             new Guid(SelectedReportId),
             generateTokenRequestParameters);

     await Interop.ShowReport(
         JSRuntime,
         PowerBIElement,
         tokenResponse.Token,
         report.EmbedUrl,
         report.Id.ToString());
 }

 

 

This is the code I'm using to get the token. This is what is producing the error

Anonymous
Not applicable

HI @Anonymous,

So you mean these processes get the return the error messages that you faced and motion at the above? Have you tried to create a common function to invoke these operations instead of package into the using functions?

The GC may affect the await processings, perhaps you can add some output trace to confirm these required parameters has correctly generated in your codes processings.

BTW, are you worked with fabric API? AFAIK, current it seems not support service principal.

Microsoft Fabric REST APIs for automation and embedded analytics - Microsoft Fabric REST APIs | Microsoft Learn

Regards,
Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.