azureauthenticationpowerbinon-interactive

Getting 403 Forbidden when Authenticating Non-Interactively to Azure REST API for PowerBi Embedded Report


I am new to both Azure ActiveDirectory as well as Power Bi Embedded.

I have an ASP.net WebForms app that I would like to display some PowerBi Reports in. When I authenticate interactively, all works well, I get my token and am able to access my report. (Follwing the excellent examples found on GitHub) These examples are interactive logins and use the AcquireTokenByAuthorizationCode() method.

However, I don't want my users to have to create / login with any account, just want to render the report for their consumption.

So I have setup a ClientCredential (cc) with my clientID and clientSecret. Am using this with the AquireToken method thusly:

 token = AC.AcquireToken("https://analysis.windows.net/powerbi/api",cc).AccessToken;

This successfully gets me a token, however, when I add that to the request header:

 request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken.Value));

The Response always fails with a "403 Forbidden" error at:

 using (var response = request.GetResponse() as System.Net.HttpWebResponse)
    {}

I've looked at other examples, many are using the async methods to aquire a token, which I am not.

Can anyone advise on how I can get past these 403 errors so I can simply serve up reports to my users (I don't want to publish them publicly, due to security concerns).

Thank you kindly in advance!


Solution

  • Doh, I was doing it wrong! Azure Login is not necessarily required to embed reports securely. The 3rd link below is included because my app is not MVC but WebForms, and Mr. Mikami shared a nice code sample which I tweaked to help me achieve my goal.

    For anyone else looking to use Power Bi Embedded to embed reports, and authenticate non-interactively, these 3 links helped get me there.