【发布时间】: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;
}
使用这些值:
- authorityUrl:https://login.windows.net/common/oauth2/authorize/
- resourceUrl:https://analysis.windows.net/powerbi/api
- 我从 PowerBI 注册应用程序时的 clientId 和 clientSecret(另外,我在 Azure 门户中检查了 ApplicationId,它是相同的)
现在,我遇到了一个错误:
响应状态码不表示成功:400 (BadRequest)。
[AdalServiceException:AADSTS90002:未找到租户“授权”。如果租户没有活动订阅,则可能会发生这种情况。检查以确保您拥有正确的租户 ID。请咨询您的订阅管理员。
我不知道问题是什么。我发现这个post很有用。
【问题讨论】:
-
您的目标是哪个 power bi API? v3?
-
根据错误,您已启用 MFA。所以我们不能使用
UserPasswordCredential来获取token。我建议您使用授权码获取令牌:docs.microsoft.com/en-us/power-bi/developer/embedded/…
标签: c# azure-active-directory powerbi-embedded