public static ReportWithRlsEmbeddingData GetReportWithRlsEmbeddingData()
        {
            var userName = "******";

            PowerBIClient pbiClient = TokenManager.GetPowerBiClient();

            var report     = pbiClient.Reports.GetReportInGroup(workspaceId, reportWithRlsId);
            var datasetId  = report.DatasetId;
            var embedUrl   = report.EmbedUrl;
            var reportName = report.Name;

            Console.WriteLine("Getting RLS-enabled embed tokens");

            GenerateTokenRequest tokenRequestAllData =
                new GenerateTokenRequest(accessLevel: "view",
                                         identities: new List <EffectiveIdentity> {
                new EffectiveIdentity(username: userName,
                                      datasets: new List <string> {
                    datasetWithRlsId.ToString()
                },
                                      roles: new List <string> {
                    "Admin"
                })
            });


            string embedTokenAllData = pbiClient.Reports.GenerateTokenInGroup(workspaceId, reportWithRlsId, tokenRequestAllData).Token;

            EffectiveIdentity identityWesternSales = new EffectiveIdentity(username: userName, roles: new List <string> {
                "Western Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestWesternSales = new GenerateTokenRequest("view", null, identities: new List <EffectiveIdentity> {
                identityWesternSales
            });
            string embedTokenWesternSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestWesternSales).Token;

            EffectiveIdentity identityCentralSales = new EffectiveIdentity(username: userName, roles: new List <string> {
                "Central Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestCentralSales = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityCentralSales
            });
            string embedTokenCentralSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestCentralSales).Token;

            EffectiveIdentity identityEasternSales = new EffectiveIdentity(userName, roles: new List <string> {
                "Eastern Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestEasternSales = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityEasternSales
            });
            string embedTokenEasternSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestEasternSales).Token;


            EffectiveIdentity identityCombo = new EffectiveIdentity(userName, roles: new List <string> {
                "Central Region", "Eastern Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestCombo = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityCombo
            });
            string embedTokenCombo = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestCombo).Token;


            return(new ReportWithRlsEmbeddingData {
                reportId = report.Id.ToString(),
                reportName = reportName,
                embedUrl = embedUrl,
                embedTokenAllData = embedTokenAllData,
                embedTokenWesternSales = embedTokenWesternSales,
                embedTokenCentralSales = embedTokenCentralSales,
                embedTokenEasternSales = embedTokenEasternSales,
                embedTokenCombo = embedTokenCombo
            });
        }
示例#2
0
        public static ReportWithRlsEmbeddingData GetReportWithRlsEmbeddingData()
        {
            var userName = "******";

            PowerBIClient pbiClient = TokenManager.GetPowerBiAppOnlyClient();

            var report     = pbiClient.Reports.GetReportInGroup(workspaceId, reportWithRlsId);
            var datasetId  = report.DatasetId;
            var embedUrl   = "https://app.powerbi.com/reportEmbed";
            var reportName = report.Name;

            GenerateTokenRequest tokenRequestAllData =
                new GenerateTokenRequest(accessLevel: "view",
                                         identities: new List <EffectiveIdentity> {
                new EffectiveIdentity(username: userName,
                                      datasets: new List <string> {
                    datasetWithRlsId.ToString()
                },
                                      roles: new List <string> {
                    "All Data"
                })
            });

            string embedTokenAllData = pbiClient.Reports.GenerateTokenInGroup(workspaceId, reportWithRlsId, tokenRequestAllData).Token;

            EffectiveIdentity identityWesternSales = new EffectiveIdentity(username: userName, roles: new List <string> {
                "Western Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestWesternSales = new GenerateTokenRequest("view", null, identities: new List <EffectiveIdentity> {
                identityWesternSales
            });
            string embedTokenWesternSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestWesternSales).Token;

            EffectiveIdentity identityCentralSales = new EffectiveIdentity(username: userName, roles: new List <string> {
                "Central Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestCentralSales = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityCentralSales
            });
            string embedTokenCentralSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestCentralSales).Token;

            EffectiveIdentity identityEasternSales = new EffectiveIdentity(userName, roles: new List <string> {
                "Eastern Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestEasternSales = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityEasternSales
            });
            string embedTokenEasternSales = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestEasternSales).Token;

            EffectiveIdentity identityCombo = new EffectiveIdentity(userName, roles: new List <string> {
                "Central Region", "Eastern Region"
            }, datasets: new List <string> {
                datasetWithRlsId.ToString()
            });
            GenerateTokenRequest tokenRequestCombo = new GenerateTokenRequest(accessLevel: "view", datasetId: datasetId, identities: new List <EffectiveIdentity> {
                identityCombo
            });
            string embedTokenCombo = pbiClient.Reports.GenerateTokenInGroup(workspaceId, report.Id, tokenRequestCombo).Token;


            return(new ReportWithRlsEmbeddingData {
                reportId = report.Id.ToString(),
                reportName = reportName,
                embedUrl = embedUrl,
                embedTokenAllData = embedTokenAllData,
                embedTokenWesternSales = embedTokenWesternSales,
                embedTokenCentralSales = embedTokenCentralSales,
                embedTokenEasternSales = embedTokenEasternSales,
                embedTokenCombo = embedTokenCombo
            });
        }