2
votes

I'm trying do develop an application that makes use of the Power BI API.

The problem is, even though I have a valid authentication token, every API endpoint I tried to access so far returns a 403 (Forbidden) Http status with no content on the response body.

I think the token I'm getting is valid because when I try to use the same token the next day it gives me a "Token expired message".

I'm using a corporative Azure Active Directory account where I'm not an administrator. But I have full access to the Power BI workspaces and Reports on it's web interface.

I'm currently authenticating with Azure AD Oatuh2 v1 but I also tryed v2 with no success (I'm still using v1 because on v2 I'm not sure my scope and resource parameters are right).

Here are the requests I'm sending:

GET
https://login.microsoftonline.com/{tenant}/oauth2/authorize?
client_id=<my client id>
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%3A8080/azureLogin/authorize
&response_mode=query

get the authorization code on the redirect at localhost:8080/azureLogin/authorize then

POST https://login.microsoftonline.com/{tenant}/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&client_id=<my client id>
&code=<the code I just got>
&redirect_uri=http%3A%2F%2Flocalhost%3A8080/azureLogin/authorize
&client_secret=<my client secret>

As "tenant" I tried both "common" and my organization id.

But when I try to access https://api.powerbi.com/v1.0/myorg/reports with the Authorization: Bearer <token> header. I get a 403 Forbiden response.

On Azure AD I can see my user has given all permissions to this application I registered.

Am I missing something? How can I solve that?

1
I don't see a resource parameter: https://analysis.windows.net/powerbi/api So it's not clear that you have a valid token for Power BI. - David Browne - Microsoft
@DavidBrowne-Microsoft It worked. Thank you very much. You saved my day. Can't accept your comment as a response though. - ylima

1 Answers

1
votes

To make the answer visible to others, I'm summarizing the answer shared in comment:

You missed the resource parameter, you are access powerbi, so it should be

resource: https://analysis.windows.net/powerbi/api

The resource is app ID URI of the target web API (secured resource). It may also be an external resource like https://graph.microsoft.com, https://analysis.windows.net/powerbi/api etc. This is required in one of either the authorization or token requests.