由于有效身份中缺少角色,无法生成用于访问数据集的嵌入令牌 [英] Unable to generate embed token for accessing dataset due to missing roles in effective identity

查看:5
本文介绍了由于有效身份中缺少角色,无法生成用于访问数据集的嵌入令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我嵌入了 powerbi 报告,在我更改数据库之前它工作正常.

I have embedded powerbi report which was working fine until I changed my database.

我观察到 datasets.IsEffectiveIdentityRequired(在下面的代码中)之前是错误的,现在它是真的,我收到一个错误 - {"error":{"code":"InvalidRequest","message":"Creating用于访问数据集 02c90e15-35dd-4036-a525-4f5d158bfade 的嵌入令牌要求角色包含在提供的有效身份中"}}

I observed datasets.IsEffectiveIdentityRequired (in below code) was false earlier, now as it is true, I'm getting an error - {"error":{"code":"InvalidRequest","message":"Creating embed token for accessing dataset 02c90e15-35dd-4036-a525-4f5d158bfade requires roles to be included in provided effective identity"}}

我正在使用标准的嵌入服务代码.

I'm using standard Embed service code.

//创建 Power BI 客户端对象.它将用于调用 Power BI API.

// Create a Power BI Client object. It will be used to call Power BI APIs.

            using (var client = new PowerBIClient(new Uri(ApiUrl), m_tokenCredentials))
            {
                // Get a list of reports.
                var reports = await client.Reports.GetReportsInGroupAsync(WorkspaceId);


                Report report = reports.Value.FirstOrDefault(r => r.Id.Equals(ReportId, StringComparison.InvariantCultureIgnoreCase));

                var datasets = await client.Datasets.GetDatasetByIdInGroupAsync(WorkspaceId, report.DatasetId);
                m_embedConfig.IsEffectiveIdentityRequired = datasets.IsEffectiveIdentityRequired;
                m_embedConfig.IsEffectiveIdentityRolesRequired = datasets.IsEffectiveIdentityRolesRequired;
                GenerateTokenRequest generateTokenRequestParameters;
                // This is how you create embed token with effective identities
                // HERE username IS NULL
                if (!string.IsNullOrWhiteSpace(username))
                {
                    var rls = new EffectiveIdentity(username, new List<string> { report.DatasetId });
                    if (!string.IsNullOrWhiteSpace(roles))
                    {
                        var rolesList = new List<string>();
                        rolesList.AddRange(roles.Split(','));
                        rls.Roles = rolesList;
                    }
                    // Generate Embed Token with effective identities.
                    generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls });
                }
                else
                {
                    // Generate Embed Token for reports without effective identities.
                    generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                }

                var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(WorkspaceId, report.Id, generateTokenRequestParameters);

}

首先,我完全理解发生此错误是因为我没有传递任何身份.那么,是否有任何选项可以禁用 IsEffectiveIdentityRequired?

First, I completely understand that this error occurs as I'm not passing any identity. So, is there any option to disable IsEffectiveIdentityRequired?

二、powerbi中如何设置用户和角色?--我不是 PowerBI 专家--

Second, how to set users and roles in powerbi? --I'm not a PowerBI expert--

推荐答案

IsEffectiveIdentityRequired 是只读属性,因此您无法控制它,也没有选项禁用它.

IsEffectiveIdentityRequired is a read only property so you can't control it and there is no option to disable it.

根据您连接到有效身份的数据源,可能需要也可能不需要.

Depending on the data source you are connecting to an effective identity may or may not be required.

如果 IsEffectiveIdentityRequired 为 true,则在调用 GenerateTokenRequest 以生成嵌入令牌时需要传递 EffectiveIdentity.如果数据源需要一个有效的身份,而您没有传递一个,那么在调用 GenerateTokenRequest 时会出错.如果传递的 EffectiveIdentity 不完整,例如调用 GenerateTokenRequest 时缺少角色,也会出现错误.

If IsEffectiveIdentityRequired is true you need to pass an EffectiveIdentity when calling GenerateTokenRequest to generate an embed token. If the data source requires an effective identity and you do not pass one you will get an error when calling GenerateTokenRequest. You will also get an error if you pass an incomplete EffectiveIdentity, such as one that is missing roles when calling GenerateTokenRequest.

这是一个示例,说明如何使用 IsEffectiveIdentityRequired 属性根据数据源是否需要它来生成具有或不具有有效身份的嵌入令牌.

Here is an example of how you can use the IsEffectiveIdentityRequired property to generate an embed token with or without an effective identity depending on if the data source requires it or not.

                List<EffectiveIdentity> eil = new List<EffectiveIdentity>();
                EffectiveIdentity ef = new EffectiveIdentity();

                // UserName
                ef.Username = FullADUsername;

                // Roles
                List<string> Roles = new List<string>();

                ef.Roles = Roles;

                // Datasets
                List<string> _Datasets = new List<string>();
                _Datasets.Add(report.DatasetId);
                ef.Datasets = _Datasets;

                eil.Add(ef);

                // Look up the data set of the report and look if we need to pass an Effective Identify               
                Dataset d = client.Datasets.GetDatasetByIdInGroup(WorkspaceId, report.DatasetId);
                if (d.IsEffectiveIdentityRequired == true)
                {
                    GenerateTokenRequest gtr = new GenerateTokenRequest("View", null, false, eil);
                    newEmbedToken = client.Reports.GenerateTokenInGroup(WorkspaceId, ReportId, gtr);
                }
                else
                {
                    GenerateTokenRequest gtr = new GenerateTokenRequest();
                    newEmbedToken = client.Reports.GenerateTokenInGroup(WorkspaceId, ReportId, gtr);
                }

这篇关于由于有效身份中缺少角色,无法生成用于访问数据集的嵌入令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆