我已经上传了一个带有自定义角色的pbix文件,我现在正尝试将此角色应用于嵌入式报告,但我不知道如何正确添加自定义标头以添加我对该角色的请求。我可以找到的唯一参考是https://docs.microsoft.com/en-ca/azure/power-bi-workspace-collections/app-token-flow
但它引用了已弃用的" Power BI工作区集合"。我在很多使用的电话中都看到了customHeader参数,但我不知道如何正确使用它。
我正在尝试将此用于我公司的多租户解决方案,我希望确保客户只能访问他们的数据。我认为我正朝着正确的方向前进,但如果没有,请告诉我。
public async Task<ActionResult> GetReportEmbedded()
{
// Create a user password credentials.
var accessToken = await GetTokenCredentials();
var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
// Generate Embed Token.
//using (FileStream fileStream = new FileStream(powerBi.Value.pbixPath, FileMode.Open, FileAccess.Read))
using (var client = new PowerBIClient(new Uri(powerBi.Value.ApiUrl), tokenCredentials))
using (Task<Group> tableTalkGroup = client.Groups.GetGroupsWithHttpMessagesAsync()
.ContinueWith(task => task.Result.Body.Value.First(group => @group.Name == "*** group name ***")))
using (Task<Report> reportTask = client.Reports.GetReportsInGroupWithHttpMessagesAsync((await tableTalkGroup).Id).ContinueWith(task => task.Result.Body.Value.First(report => report.Name == "Power BI Template")))
{
Dictionary<string, List<string>> headerDictionary = new Dictionary<string, List<string>>();
headerDictionary.Add("roles", new List<string>{ "***custom role***" });
var tokenResponse = await client.Reports.GenerateTokenInGroupWithHttpMessagesAsync(
(await tableTalkGroup).Id, (await reportTask).Id, new GenerateTokenRequest(accessLevel: "view"),
headerDictionary, CancellationToken.None);
// Generate Embed Configuration.
var embedConfig = new EmbedConfig()
{
EmbedToken = tokenResponse.Body,
EmbedUrl = (await reportTask).EmbedUrl,
Id = (await reportTask).Id
};
return View(embedConfig);
}
}