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

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.

Reply
Anonymous
Not applicable

Invalid status code 'Forbidden'

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();

}

 

 

 

4 REPLIES 4
Eric_Zhang
Employee
Employee


@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);
Anonymous
Not applicable

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)?

Anonymous
Not applicable

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.