0

I want automatic login to view power bi reports with iframe in mvc application.

For this, I created an application in Azure AD and gave all read permissions in the delegated permissions.

For this i created a class and get access token. But when i call service with token i get unauthorized error.

The class I created is as follows;

 public async Task<string> GetAccessTokenAsync()
 {
     IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(clientId)
         .WithClientSecret(clientSecret)
         .WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
         .Build();


     string[] scopes = new string[] { "https://analysis.windows.net/powerbi/api/.default" };
     AuthenticationResult result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
     Console.WriteLine("token: " + result.AccessToken);
     return result.AccessToken;
 }


 public async Task<string> GetReportsAsync()
 {
     string accessToken = await GetAccessTokenAsync();

     using HttpClient client = new HttpClient();
     client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

     HttpResponseMessage response = await client.GetAsync("https://api.powerbi.com/v1.0/myorg/reports");
     return await response.Content.ReadAsStringAsync();
 }

How can I solve this problem?

1 Answer 1

0

This api call gets the reports from My Workspace:

https://api.powerbi.com/v1.0/myorg/reports

However since the application registration doesn't have a personal workspace, an error is returned.


I recommend using this api call instead:

https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}

This call returns an embed url that can be used to embed the Power BI report directly into your application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.