连接到Power BI API时收到“禁止(403)”

力马克

我们一直在尝试阅读这篇Power BI文章,以便可以将报告/仪表板嵌入到我们的SaaS产品中。具体来说,我们停留在第3步“创建嵌入令牌”。

我们能够很好地获得承载令牌,但是当检索报告的请求最终提交给API时,我们会收到:操作返回了无效的状态码“禁止”

    private static string clientId = "...";
    private static string secretKey = "...";
    private static string groupId = "...";

    static void Main(string[] args)
    {
        string resourceUri = "https://analysis.windows.net/powerbi/api";
        string authorityUri = "https://login.windows.net/common/oauth2/authorize";

        ClientCredential credential = new ClientCredential(clientId, secretKey);
        AuthenticationContext authContext = new AuthenticationContext(authorityUri);

        var token = authContext.AcquireTokenAsync(resourceUri, credential).Result.AccessToken;

        var tokenCredentials = new TokenCredentials(token, "Bearer");

        using (var client = new PowerBIClient(new Uri("https://api.powerbi.com/"), tokenCredentials))
        {
            var reports = client.Reports.GetReportsInGroupWithHttpMessagesAsync(groupId);

            // !!! - Here's where the exception is thrown
            // !!! -- Operation returned an invalid status code 'Forbidden'
            var report = reports.Result.Body;
        }
    }

这是我们尝试过的方法:

  • 已授予必需的权限(我们已选中所有权限以确保我们不会丢失任何内容)。这包括Windows Azure Active Directory / Power BI服务。
  • 我们已经确认客户ID,秘密密钥和组ID是正确的。
  • Power BI工作空间是私有的,但是我们尝试将其设为公共空间以确保无关紧要。
  • 最后,我们通过代码收到的令牌与powerbi.com上的令牌匹配。
Nan Yu

您正在使用客户端凭证流来获取Power BI API的令牌。当前,Power BI REST API仅支持委派权限,但不支持任何应用程序权限。因此,您的访问令牌没有足够的访问权限。要使用Power BI,身份验证需要基于特定用户。这里这里的相关主题供您参考。

根据您的文档,该场景是应用拥有对数据的访问权。用户不一定是Power BI用户,并且该应用程序控制最终用户的身份验证和访问。然后,您可以使用资源所有者流来获取令牌。

应用拥有数据”示例的Controllers \ HomeController.cs中提供了一个示例。

从代码示例中,它使用用户密码凭据而非应用程序的凭据来获取令牌:

            // Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

请参阅对用户进行身份验证,并为您的Power BI应用程序获取Azure AD访问令牌,然后检查Access token for non-Power BI users (app owns data)部分。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Power BI API限制

将AWS PostgreSQL连接到Power BI Desktop:证书中不存在指定的主机名

一对多连接时,如何用Power BI中的值替换NULL

将Oracle DB与Power BI连接时出现错误

使用自定义连接器将Microsoft Graph API报告数据导入Power BI

将Azure Analysis Service连接到Traffic Manager和Power BI

Power BI比较日期

使用Python连接到Power BI XMLA端点

Power BI YTD计算

使用Power BI REST API 403错误生成嵌入令牌

Power BI始终返回403禁止

无法使用API更改Power BI连接字符串

雪花+ Power BI连接

Powershell-自动连接到Power BI服务,无需硬编码密码

无法将Power BI连接到Hadoop HDFS未能获取内容

我们可以将数据源连接到Power Bi中的多个本地数据库吗?

在“我的工作空间”中获取仪表板时,禁止Power BI API返回403

Power BI REST API:导入数据

使用rcurl连接到BI工具的REST API

尝试在 Azure HDInsight 连接器中使用 Spark 导入 Power BI 中的数据时出错

如何仅通过 dataGateway 将 Power BI 连接到 MS SQL

Neo4j:与 Power Bi 的连接

在 Power BI 中将两个独立的数据库连接到桌面版本和服务器上

如何在没有第三方软件的情况下将 Apache Druid 连接到 Power BI?

通过直接查询连接到 Azure 专用 SQL 池的 Power BI 报告性能缓慢

Power BI:获取数据 - 无法连接 - 详细信息:“禁止访问该资源。”

筛选 LOOKUPVALUE (Power BI)

尝试将 Power BI 服务连接到 Snowflake - PBI 服务使用什么 IP 地址?

坚持在模型中创建连接 - Power BI