gpt4 book ai didi

c# - 使用服务主体对 GetReportInGroupAsync PowerBI Embedded API 调用进行未经授权的响应

转载 作者:行者123 更新时间:2023-12-04 02:31:48 33 4
gpt4 key购买 nike

我正在尝试将 Power BI 报告嵌入到我的 .Net Core 应用程序中,但是我无法从请求中获得有效的响应。我正在使用 Microsoft.PowerBI.API 包和一个向服务主体注册的 azure 应用程序。
据我所知,我已经按照此处的说明使用正确的权限设置了 AAD 和服务主体:
https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal
在将该安全组添加到 Power BI 管理门户中的管理设置之前,我发现了您必须将 AAD/服务主体添加到安全组的部分。
这是我正在使用的代码片段:

var AuthorityUrl = "https://login.microsoftonline.com/common/";
var ResourceUrl = "https://analysis.windows.net/powerbi/api";

var authenticationContext = new AuthenticationContext(AuthorityUrl);
AuthenticationResult authenticationResult = null;
var credential = new ClientCredential("application_id", "application_secret");
authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, credential);

using (var client = new Microsoft.PowerBI.Api.PowerBIClient(new Uri("https://api.powerbi.com/"), new TokenCredentials(authenticationResult.AccessToken, "Bearer")))
{
var report = await client.Reports.GetReportInGroupAsync(new Guid("workspace_id"), new Guid("report_id"));
}
我成功地从 AcquireTokenAsync 取回了 token 打电话,但是当我得到报告时,我得到了一个未经授权的。
以下是我在 Azure 中的 AAD/服务主体的权限:
azure aad api permissions
这是我用 Fiddler 捕获的请求/响应。
要求:
GET https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id} HTTP/1.1
Authorization: Bearer {access_token}
User-Agent: FxVersion/4.6.28207.03 OSName/Windows OSVersion/Microsoft.Windows.10.0.18362. Microsoft.PowerBI.Api.PowerBIClient/3.14.01300.0002
Host: api.powerbi.com
回复:
HTTP/1.1 401 Unauthorized
Content-Length: 0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: RequestId
request-redirected: true
home-cluster-uri: https://wabi-west-us-redirect.analysis.windows.net/
RequestId: {request_id}
Date: Thu, 10 Sep 2020 16:23:07 GMT
任何帮助,将不胜感激!

最佳答案

要使服务主体适用于任何嵌入,您需要在 Power BI 管理门户中启用服务主体选项,然后将其添加到 Power BI 工作区。
请检查以下内容一次:

  • 检查是否在 Power BI 服务的管理门户下启用了服务主体。
    关注 step 3
  • 如果按照上述步骤操作后仍然不适合您,请尝试与开发人员嵌入 sample

  • 此外,根据您的代码,您似乎正在使用 ADAL 库进行身份验证。微软 recommends to use MSAL library用于使用 Azure AD 实体进行身份验证。
    此外,您可以使用证书而不是应用程序 secret 进行服务主体身份验证。 ( Docs )

    关于c# - 使用服务主体对 GetReportInGroupAsync PowerBI Embedded API 调用进行未经授权的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63837108/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com