Forum Discussion

matoxin's avatar
matoxin
Frequent Visitor
5 years ago

Power BI API with service principal - 401 unauthorized

Hello everyone,

 

recently I have been trying to make Power BI APIs work with service principal authentication. All steps mentioned in this article https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal are done:

- an Azure AD app is registered (service principal created)

- an AD security group is created, the app is added to this group

- a Power BI admin has enabled service principal access in the admin portal

- the service principal and the security group are added to the workspace (and granted the admin role)

I am able to generate an access token using the POST method for https://login.microsoftonline.com/common/oauth2/token (screenshot below).

The issue is that whenever this token is used for any further calls (I have tried both non-admin and admin APIs - when it comes to admin ones, I only tested the supported APIS - can be seen in this article https://docs.microsoft.com/en-us/power-bi/admin/read-only-apis-service-principal-authentication), I am shown the 401 unauthorized error.

 

So my question is: did I overlook some security setting perhaps? Our company uses MFA, but service principals do not use that from what I have found on this forum/in the documentation. Or is the generated token invalid somehow?

 

Any help is greatly appreciated.

14 Replies

  • Hi,

     

    What API Permissions are set up in your App Registration for Power BI? Everything else seems ok.

    • matoxin's avatar
      matoxin
      Frequent Visitor

      Hello, at the moment, the app has the following API permissions:

      - Dataset.ReadAll

      - Report.ReadAll

      - Workspace.ReadAll

      I assume that Tenant.ReadAll should be added as well - is that correct?

  • v-lionel-msft's avatar
    v-lionel-msft
    Icon for Community Support rankCommunity Support

    Hi matoxin ,

     

    Considerations and limitations 

    Have you checked these considerations and limitations?

     

    Best regards,
    Lionel Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • matoxin's avatar
      matoxin
      Frequent Visitor

      Hello Lionel,

      yes, we have checked that article multiple times - to make sure we have not forgotten anything.

  • Mthompson1984's avatar
    Mthompson1984
    Frequent Visitor

    I'm curious if you were ever able to resolve this - I'm having the same issue.  401 unauthorized on all calls.

    • matoxin's avatar
      matoxin
      Frequent Visitor

      No, not yet - still trying to figure this out. Will update the thread if I find anything.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, we are experiencing a similar problem. Were you able to solve the issue?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, I meet tyhe same issue, could you please share your solution, thanks