我正在尝试开发一个使用 Power BI API 的应用程序.
问题是,即使我有一个有效的身份验证 token ,到目前为止我尝试访问的每个 API 端点都会返回 403(禁止)Http 状态,响应正文中没有任何内容。
我认为我获得的 token 是有效的,因为当我第二天尝试使用相同的 token 时,它会给我一条“ token 过期消息”。
我使用的是法人 Azure Active Directory 帐户,但我不是管理员。但我可以完全访问 Power BI 工作区和报告 web interface .
我目前正在使用 Azure AD Oatuh2 v1 进行身份验证但我也尝试过v2没有成功(我仍在使用 v1,因为在 v2 上我不确定我的范围和资源参数是否正确)。
以下是我发送的请求:
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
在 localhost:8080/azureLogin/authorize
的重定向上获取授权码那么
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>
作为“租户”,我尝试了“common”和我的组织 ID。
但是当我尝试访问https://api.powerbi.com/v1.0/myorg/reports
时与 Authorization: Bearer <token>
header 。我收到 403 Forbiden 响应。
在 Azure AD 上,我可以看到我的用户已向我注册的此应用程序授予所有权限。
我错过了什么吗?我该如何解决这个问题?
最佳答案
为了让其他人看到答案,我总结了评论中分享的答案:
您错过了资源参数,您正在访问powerbi,所以应该是
resource: https://analysis.windows.net/powerbi/api
资源是目标 Web API(安全资源)的应用 ID URI。它也可能是外部资源,例如 https://graph.microsoft.com , https://analysis.windows.net/powerbi/api等等。这是授权或 token 请求之一所必需的。
关于azure - Power BI 始终返回 403 Forbidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57333660/