Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi -
I am using PowerBIClient to get the reports and I get 'Forbidden' error back.
This is what i did:
string authorityUrl = "https://login.windows.net/common/oauth2/authorize";
string resouurceUrl = "https://analysis.windows.net/powerbi/api";
var authenticationContext = new AuthenticationContext(authorityUrl);
var credential = new ClientCredential(clientID, clientSecret);
AuthenticationResult result = authenticationContext.AcquireTokenAsync(resouurceUrl, credential).Result;
var token = new TokenCredentials(result.AccessToken, "Bearer");
using (var client = new PowerBIClient(new Uri("https://api.powerbi.com"), token))
{
ODataResponseListReport reports = client.Reports.GetReports();
}
@Anonymous wrote:
Hi -
I am using PowerBIClient to get the reports and I get 'Forbidden' error back.
This is what i did:
string authorityUrl = "https://login.windows.net/common/oauth2/authorize";
string resouurceUrl = "https://analysis.windows.net/powerbi/api";var authenticationContext = new AuthenticationContext(authorityUrl);
var credential = new ClientCredential(clientID, clientSecret);
AuthenticationResult result = authenticationContext.AcquireTokenAsync(resouurceUrl, credential).Result;
var token = new TokenCredentials(result.AccessToken, "Bearer");
using (var client = new PowerBIClient(new Uri("https://api.powerbi.com"), token)){
ODataResponseListReport reports = client.Reports.GetReports();
}
@Anonymous
Usually Forbidden error indicates the registered app doesn't have suffiecient permission, please check premissions in azure portal.
What is the scenario in your case, App Owns Data or User Owns Data? For App Owns data, a native app(no client_secret) is required that code snippet is like
// Create a user password cradentials. var credential = new UserPasswordCredential({Username}, {Password}); // Authenticate using created credentials var authenticationContext = new AuthenticationContext(AuthorityUrl); var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);
Hi Eric,
Thanks for your reply. My app is not a native app.
And I checked for permissions and PowerBI Service has all the delegate permissions checked, including Read and Write reports.
Please let me know if there is anything else you can think of.
Thanks, Shilpi
@Anonymous
So you're in the scenaio Embedding with Power BI users (users own data)?
Hi @Eric_Zhang,
I went with the App owns data approach and was able to authenticate using the username and password.
Thanks for your help.
I could not authenticate a web app using the client secret though.
Thanks, Shilpi
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
12 | |
2 | |
2 | |
1 | |
1 |