cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Zrean Frequent Visitor
Frequent Visitor

Power Bi REST API - 401 Authorization error when using Service Principals

Hi!

 

I've been following this guide while setting up my app. Everything works fine if I use password credentials flow and supply my own userame/password to get an access token. However, if I try to use client credentials flow, I get a 401 whenever I call any power bi endpoint. 

 

I also tried downloading the sample application provided here. Using "App Owns Data", I get the same results. If I use MasterUser (username/pass), everything works fine. But if I use ServicePrincipal (cliend_id/client_secret), I get 401. 

 

I understand that this is a new feature and it's just a public preview. But has anyone had any luck getting it to work?

 

More details:

Azure:

  • App registered with all available permissions for Power Bi Service.
  • Security group created with App as member.

Power BI:

  • Workspace (new type) created.
  • Service principal enabled in admin panel and Azure security group (with App as member) added.
  • The security group is added as admin in the workspace access panel.
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Power Bi REST API - 401 Authorization error when using Service Principals

Hi @Zrean ,

 

I made the Service Principal work in the "App Owns Data" demo and with the Rest APIs. It seems everything is set up correctly according to your description. Some suggestions are as follows.

1. Add the Service Principal as an admin in the workspace directly rather than add the security group. Please refer to article 5 in embed-service-principal#get-started-with-a-service-principal. We should use the Object ID.

Power-Bi-REST-API-401-Authorization-error-when-using-Service-Principals

2. The Service Principal inherit permission from the tenant rather than the Azure App permissions. 

>>>Service principals inherit the permissions for all Power BI tenant settings from their security group. To restrict permissions create a dedicated security group for service principals and add it to the 'Except specific security groups' list for the relevant, enabled Power BI settings.

3. I'm afraid you can't call the Admin REST API if the Service Principal doesn't have the permission.

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 REPLIES 5
Rahman New Member
New Member

Re: Power Bi REST API - 401 Authorization error when using Service Principals

I was able to get the auth token by using the service principal (client id, secret) however when I use the token and query (getReports) etc, it fails with 401. 

 

The trick to get the token was that the APP needs to be "Server-side web application" instead of "native".

 

However I believe the permissions are not being assigned when the app/security group is added to the Power BI API access.

 

 

Zrean Frequent Visitor
Frequent Visitor

Re: Power Bi REST API - 401 Authorization error when using Service Principals

Then you're in the same situation as me Smiley Happy I also manage to get the access token, but i can't use it.

Community Support Team
Community Support Team

Re: Power Bi REST API - 401 Authorization error when using Service Principals

Hi @Zrean ,

 

I made the Service Principal work in the "App Owns Data" demo and with the Rest APIs. It seems everything is set up correctly according to your description. Some suggestions are as follows.

1. Add the Service Principal as an admin in the workspace directly rather than add the security group. Please refer to article 5 in embed-service-principal#get-started-with-a-service-principal. We should use the Object ID.

Power-Bi-REST-API-401-Authorization-error-when-using-Service-Principals

2. The Service Principal inherit permission from the tenant rather than the Azure App permissions. 

>>>Service principals inherit the permissions for all Power BI tenant settings from their security group. To restrict permissions create a dedicated security group for service principals and add it to the 'Except specific security groups' list for the relevant, enabled Power BI settings.

3. I'm afraid you can't call the Admin REST API if the Service Principal doesn't have the permission.

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Zrean Frequent Visitor
Frequent Visitor

Re: Power Bi REST API - 401 Authorization error when using Service Principals

Thank you! Your first comment gave me an idea. My issue was that i did not add the Service Principal itself as Admin, i added the Security Group it belonged to. I was not able to choose a service pricipal in the UI when adding access permissions. Instead, i had to use the API and now everything is working fine.

 

Best regards

Community Support Team
Community Support Team

Re: Power Bi REST API - 401 Authorization error when using Service Principals

It's my pleasure. I'm glad you made it work. Thanks for sharing the details. This feature is under preview. I believe it will be easy to use when it's generally available.

 

 

Best Regards,

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