【问题标题】:Embed PowerBI with authentication error (AADSTS50076)嵌入带有身份验证错误的 PowerBI (AADSTS50076)
【发布时间】:2021-01-04 08:28:01
【问题描述】:

我想在我的 Web 应用程序中嵌入一些 PowerBI 报告。我有一个以前项目的工作代码。现在,我有一个带有新 Active Directory 和新 PowerBI 的新项目。我在 Active Directory 中创建了一个新应用程序,并且我有 TenantId。当我运行AcquireTokenAsync 时,我收到一个错误。

public async Task<bool> CreatePowerBIClient()
{
    bool rtn = false;

    if (client == null)
    {
        var credential = new UserPasswordCredential(SettingsModels.Username, SettingsModels.Password);

        var authenticationContext = new AuthenticationContext(SettingsModels.AuthorityUrl);
        var authenticationResult = await authenticationContext.AcquireTokenAsync(SettingsModels.ResourceUrl, 
                                    SettingsModels.ClientId, credential);

        if (authenticationResult != null)
        {
            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            client = new PowerBIClient(new Uri(SettingsModels.ApiUrl), tokenCredentials);
            rtn = true;
        }
    }
    else
        rtn = true;

    return rtn;
}

{"error":"interaction_required","error_description":"AADSTS50076:到期 管理员所做的配置更改,或者因为您 移动到新位置,您必须使用多因素身份验证 访问“00000009-0000-0000-c000-000000000000”。\r\n跟踪 ID: 4d6fa156-0435-4c92-9746-b0e3d6bcdb00\r\n相关 ID: 0febdcc8-cd86-46e2-a7a5-0ec0705732bb\r\n时间戳:2020-09-17 12:20:40Z","error_codes":[50076],"timestamp":"2020-09-17 12:20:40Z","trace_id":"4d6fa156-0435-4c92-9746-b0e3d6bcdb00","correlation_id":"0febdcc8-cd86-46e2-a7a5-0ec0705732bb","error_uri":"https://login. microsoftonline.com/error?code=50076","suberror":"basic_action","claims":"{"access_token":{"capolids":{"essential":true,"values":["8abf28b1-2a8a -440a-821c-9874593bec9c","9f5f13cb-276e-49fe-ad14-829ce71aef09"]}}}"}: 未知错误

我检查了 Active Directory 中应用程序设置的权限,但找不到禁用多重身份验证的位置。不过我不是这个域的管理员。

我能做什么?

更新

我正在使用最新版本的 PowerBI 包,并用建议的代码替换了代码:

public async Task<bool> CreatePowerBIClient()
{
    bool rtn = false;

    if (client == null)
    {
        var authenticationContext = new AuthenticationContext(SettingsModels.AuthorityUrl);

        var credential = new ClientCredential(SettingsModels.ClientId, SettingsModels.ClientSecret);
        var authenticationResult = await authenticationContext.AcquireTokenAsync(SettingsModels.ResourceUrl, credential);

        if (authenticationResult != null)
        {
            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            client = new PowerBIClient(new Uri(SettingsModels.ApiUrl), tokenCredentials);
            rtn = true;
        }
    }
    else
        rtn = true;

    return rtn;
}

使用这些值:

现在,我遇到了一个错误:

响应状态码不表示成功:400 (BadRequest)。

[AdalServiceException:AADSTS90002:未找到租户“授权”。如果租户没有活动订阅,则可能会发生这种情况。检查以确保您拥有正确的租户 ID。请咨询您的订阅管理员。

我不知道问题是什么。我发现这个post很有用。

【问题讨论】:

标签: c# azure-active-directory powerbi-embedded


【解决方案1】:

根据您的代码,我了解到您正在使用特定帐户获取令牌以连接到 PowerBI 报告。

您遇到的此错误表明您正在传递启用了 MFA 的帐户的凭据。 MFA 在用户帐户级别启用,而不是在应用级别启用。要克服此错误,您可以使用以下选项之一:

选项 1:

您可以尝试为您用于连接到报告的帐户寻求和豁免 MFA。或者,在许多组织中,作为最佳实践,在没有启用 MFA 的情况下使用具有最少权限的服务帐户来执行自动化任务。您可以通过授予这些帐户访问权限来使用其中一个帐户来连接到报告。

这不需要对您的代码进行任何更改。

选项 2:

您可以生成仅应用程序令牌。您正在制作一个应用程序以通过 Azure AD 进行身份验证并使用该报告。 MFA 将完全被排除在外。

应用需要获得报告所在工作区的权限。

下面的sn-p获取App only token的代码

var credential = new ClientCredential(ApplicationId, ApplicationSecret);
authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, credential);

有关如何为应用创建和授予权限的详细步骤,您可以参考此article

注意:

这需要 PowerBI 服务管理员在 PowerBI 服务上启用一个设置,以通过此方法使用报告。

【讨论】:

  • 谢谢。我现在面临一个问题。我更新了帖子。
  • 您可以尝试将 AuthorityURL 用作:https://login.microsoftonline.com/&lt;TenantGUID&gt;https://login.windows.net/common/ 吗?
  • 非常感谢!我现在有另一个问题来获取仪表板和报告的列表。我创建了一个新帖子stackoverflow.com/questions/63953987/…
猜你喜欢
  • 1970-01-01
  • 2014-06-30
  • 1970-01-01
  • 1970-01-01
  • 2017-10-13
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 2013-01-04
相关资源
最近更新 更多