Hello,
I have a web application that uses a .NET API backend and am trying to connect to PowerBI Premium to obtain the token, but every time I do I get the same error.
AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.
What I am essentially wanting to do is hit my .NET API Controller, and pass in a selected PBIX file, and then use the Power Bi SDK to upload and publish the file to the Power Bi Premium App Workspace. Then, after this part is finished, I will then be building out another section of my application where the users can go to view these power bi reports. In my application the App Owns the data, and I have bought the license and set up the user properly. I have also set up the App Workspace and set that to be Premium workspace.
I have also registered my app at https://dev.powerbi.com/apps as a Serve-side web app. The redirect URL I was confused about as I dont need it to redirect my app anywhere, as the user should not be entering credentials, but it says to just use any valid url, so I put the homepage of my app. I then gave it all permissions and got the ClientId and Secret.
Then I tried to use the same 3 or 4 lines of code that I see as exmaples in almost every site. It is a little confusing because I dont see a place to enter the Client Secret that I just obtained in registering my app, so I am not sure if that is just for viewing the reports in the app, or this too, but here are the lines of code I used that give me that error I posted above....
// Create a user password cradentials.
var credential = new UserCredential(Username, Password);
// Authenticate using created credentials
var authenticationContext = new AuthenticationContext(AuthorityUrl);
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);
var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
These are the URLs I am using in the above code....
<add key="authorityUrl" value="https://login.windows.net/common/oauth2/authorize" />
<add key="resourceUrl" value="https://analysis.windows.net/powerbi/api" />
Once I have the token, I plan to use the PowerBI SDK to upload the report like this....
var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(credentials, handler);
client.Imports.PostImportWithFileInGroup(GroupId, file1Stream, "importedreport", "Abort");
If anyone can help me understand what I am doing wrong, I would be very thankful. I am on a time crunch to get this done, and am at a point where I am not sure how to proceed. Thanks.