I have created my app and registered over https://dev.powerbi.com/Apps as Native. In Azure, I added myself ad global admin user, registered myself to the application as admin, granted all Power BI API permissions. I created a workspace, added myself an admin user. Uploaded a Power BI report in my workspace. Works well when I am on browser.
I am trying to connect my report by using ASP.NET 4.61 MVC. My credentials, username and password work, so no problem for this code below:
var credential = new UserPasswordCredential(Username, Password);
// Authenticate using created credentials
var authenticationContext = new AuthenticationContext(AuthorityUrl);
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ApplicationId, credential);
if (authenticationResult == null)
{
result.ErrorMessage = "Authentication Failed.";
return View(result);
}
var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
However, I am receiving the error: Status: Unauthorized (401)
on the line GetReportsInGroupAsync(Workspaceid);
where workspaceId is matching with my workspace.
// Create a Power BI Client object. It will be used to call Power BI APIs.
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
// Get a list of reports.
var reports = await client.Reports.GetReportsInGroupAsync(WorkspaceId);
...
}
So the reports from my workspace I cannot reach because of unauthorization error, and I could not pass it. How can I authorize myself, I am already in AAD as Global Admin, added myself as application owner and in workspace I am already registered as admin.
I've found this topic below, but the answer did not fix my issue:unauthorized error 401 for power reports embedding
Followed this guideline, also did not work: https://learn.microsoft.com/en-us/power-bi/developer/register-app
Any help would be appreciated.