c# - Power Bi 管理的 Azure AD 代表流程

标签 c# azure azure-active-directory powerbi azure-ad-msal

我成功设置了“Azure AD 代表流程”,我的 Web api 安全操作调用和 ms graph api 调用也正常工作。 不,我添加了更多与 power bi 相关的补助金。我想从 Web api 读取/写入工作区/报告等 我试过了:

string[] scopes = { "Capacity.Read.All", "Capacity.ReadWrite.All",
    "Content.Create", " Dashboard.Read.All", " Dashboard.ReadWrite.All",
    "Data.Alter_Any", "Dataset.Read.All", "Dataset.ReadWrite.All", "Group.Read", "Group.Read.All",
    "Metadata.View_Any", "Report.Read.All", "Report.ReadWrite.All", "Tenant.Read.All",
    "Workspace.Read.All", "Workspace.ReadWrite.All"};
string accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes); // error
var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(_powerBiConfig.ApiUrl), tokenCredentials))
{
...
}

但是 GetAccessTokenOnBehalfOfUser 返回

AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid.

最佳答案

我自己得到的。

下面的代码演示了如何检索所有 Power bi 工作区

public async Task<string> Groups()
{
    string[] scopes = { "https://analysis.windows.net/powerbi/api/Dataset.Read.All"};
    try
    {
        string accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
        var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
        using (var client = new PowerBIClient(new Uri(_powerBiConfig.ApiUrl), tokenCredentials))
        {
            return JsonConvert.SerializeObject(client.Groups.GetGroups().Value, Formatting.Indented);
        }
    }
    catch (Exception exc)
    {
        return string.Empty;
    }
}

关于c# - Power Bi 管理的 Azure AD 代表流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54289542/

相关文章:

azure-active-directory - 如何使用 Azure AD 进行身份验证时排除特定 URL?

c# - 模型是否包含字段而不将其添加到数据库?

c# - 验证 TextBox 中的文本更改

c# - 使用 Selenium 在现有浏览器 session 中打开一个新选项卡

c# - 为什么 azure 函数看不到配置的连接字符串?

java - 为什么在Azure AD保护的Spring boot应用程序中它被称为 'APPROLE_Admin'而不是 'Admin'

node.js - Nodemailer 无效登录 : 451 4. 7.0 临时服务器错误

c# - 在 .NET 中格式化货币

c# - 我的 AAD 身份验证回复网址有什么问题吗?

java - 增加 Spring Cloud Stream Azure 服务总线中的并发调用未定义行为