IsEffectiveIdentityRequired

IsEffectiveIdentityRequired

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

问题描述

我已经嵌入了 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);
                }

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

09-18 09:27