我有一份报告,其中我想实现行级安全性。我已经准备好了我的报告,现在剩下的就是将它嵌入到网页中。 为此,我创建了一个空白的MVC站点。 我已将我的应用程序注册到Azure AD并授予所有必需的权限。我没有任何主帐户或专业帐户。 每当用户点击URL时,我想提示用户登录,登录后,我想传递角色和用户名以报告实施RLS。
这是我的行动方法:
public async Task<ActionResult> Index()
{
try
{
AuthenticationContext AuthContext = new AuthenticationContext(AuthorityUrl, false);
string query = "client_secret="+ClientSecret;
AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, ClientID, new Uri(RedirectUrl), new PlatformParameters(0), UserIdentifier.AnyUser,query);
if (AuthResult == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Authentication Failed."
});
}
var tokenCredentials = new TokenCredentials(AuthResult.AccessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
var reports = client.Reports.GetReports();
var report = reports.Value[0];
if (report == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Workspace has no reports."
});
}
EffectiveIdentity effectidentity = new EffectiveIdentity(AuthResult.UserInfo.DisplayableId, new List<string>(new string[] { report.DatasetId }), new List<string>(new string[] {"Role1"}));
var generateTokenRequestParameters = new GenerateTokenRequest("View", report.DatasetId, false, new List<EffectiveIdentity>(new EffectiveIdentity[] { effectidentity }));
var tokenResponse = client.Reports.GenerateToken(report.Id, generateTokenRequestParameters);
if (tokenResponse == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Failed to generate embed token."
});
}
var embedConfig = new EmbedConfig()
{
Token = tokenResponse.Token,
EmbedUrl = report.EmbedUrl,
Id = report.Id
};
return View(embedConfig);
}
}
catch(Exception ex)
{
return View(new EmbedConfig()
{
ErrorMessage = "Failed to display report."
});
}
}
在此行AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, ClientID, new Uri(RedirectUrl), new PlatformParameters(0));
之后,它会询问用户凭据。
在var tokenResponse = client.Reports.GenerateToken(report.Id, generateTokenRequestParameters);
行,它提供了Operation returned an invalid status code 'Forbidden'
的例外情况。
由于我没有任何专业用户,我无法创建组ID。在这种情况下,我不能使用GenerateTokenInGroup,因为我没有任何组。
在这种情况下该怎么办?
答案 0 :(得分:-1)
嵌入Power BI工件仅适用于Power BI的高级用户。 https://docs.microsoft.com/en-us/power-bi/service-premium
或通过Azure:https://powerbi.microsoft.com/en-us/blog/power-bi-developer-community-october-update/