Power BI Embedded API 问题和 401 未经授权错误

问题描述 投票:0回答:1

我正在致力于使用 REST API 集成 Power BI Embedded 来检索仪表板列表。我正在使用具有正确客户端 ID 和客户端密钥的客户端凭据流来获取访问令牌。

我的应用程序已在 Azure AD 中注册,并且我已授予 Dashboard.Read.All 权限(委托类型)。但是,尽管拥有有效的令牌,但在尝试访问 API 端点 (../v1.0/myorg/dashboards) 时,我仍然收到 401 未经授权的错误。我已确保令牌作为不记名令牌包含在请求标头中。有没有人遇到过类似的问题或者知道是什么原因造成的?

powerbi unauthorized azure-app-registration powerbi-rest-api
1个回答
0
投票

注意: 不支持客户端凭据流访问

myorg
,因为它属于服务主体身份验证。要使仪表板出现在
myorg
中,您需要使用授权代码流生成令牌。

最初,我注册了 Microsoft Entra ID 应用程序,添加并授予 API 权限,如下所示:

enter image description here

为了获得

code
,我在浏览器中运行了授权请求

https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?  
client_id=<client_id>
&response_type=code  
&redirect_uri=https://jwt.ms
&response_mode=query  
&scope=https://analysis.windows.net/powerbi/api/.default
&state=12345

enter image description here

现在,我使用带有以下参数的authorization_code流程生成了访问令牌:

https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token 
client_id=<app_id>
client_secret = <client_secret>
redirect_uri= https://jwt.ms
code=<code which generated from browser>
scope= https://analysis.windows.net/powerbi/api/.default
grant_type = authorization_code

回复:

enter image description here

当我使用此生成的访问令牌来列出工作区中的仪表板时,我得到了如下响应。

要列出工作区中的仪表板:

GET https://api.powerbi.com/v1.0/myorg/dashboards

enter image description here

由于我的工作区中没有任何仪表板,因此使用

Status 200 OK
为空值。

如果问题仍然存在,请确保使用 AdminContributor 访问权限将 Entra ID 注册应用程序添加到 Power BI 工作区。

参考:

获取仪表板 - Power BI REST API

MsDoc-使用服务主体和客户端密钥嵌入 Power BI 内容

© www.soinside.com 2019 - 2024. All rights reserved.