我正在努力为本地 ssas 连接创建嵌入令牌。最终目标是传递安全性,以便我可以在 power bi 中使用 ssas 中的角色安全性。
但是,我的第一步是生成初始嵌入令牌。由于我是嵌入新手,这正在变成一种折磨。
我能够使用以下代码为带有 RLS 的常规 Power BI 数据集成功创建嵌入令牌。
这与我昨天发布的类似帖子相关。不过,我现在已经可以使用它了,我正在尝试在 Prem 上进行 SSAS。我的安全设置与上面的帖子相同。除了我将 Azure AD 应用程序注册添加到工作区和我正在使用的网关中。
private static bool useEmbedToken = true;
private static bool useRLS = true;
private static string authorityUrl = "https://login.microsoftonline.com/organizations/";
private static string resourceUrl = "https://analysis.windows.net/powerbi/api";
private static string apiUrl = "https://api.powerbi.com/";
private static string tenantId = "TENANT"; //Working
private static Guid groupId = Guid.Parse("GROUP");
private static Guid reportId = Guid.Parse("REPORT");//
private static Guid datasetId = Guid.Parse("DATASET"); //
// **** Update the Client ID and Secret within Secrets.cs ****
private static ClientCredential credential = null;
private static AuthenticationResult authenticationResult = null;
private static TokenCredentials tokenCredentials = null;
static void Main(string[] args)
{
//try
{
// Create a user password cradentials.
credential = new ClientCredential(Secrets.ClientID, Secrets.ClientSecret);
// Authenticate using created credentials
Authorize().Wait();
using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
{
#region Embed Token
EmbedToken embedToken = null;
if (useEmbedToken && !useRLS)
{
}
else if (useEmbedToken && useRLS)
{
// **** With RLS ****
var rls = new EffectiveIdentity(username: "USER@COMPANY.com", new List<string> { datasetId.ToString() });
var rolesList = new List<string>();
rolesList.Add("Role");
rls.Roles = rolesList;
embedToken = client.Reports.GenerateTokenInGroup(groupId, reportId,
new GenerateTokenRequest(accessLevel: "View", datasetId: datasetId.ToString(), rls));
//var generateTokenRequestParameters = new GenerateTokenRequestV2(
// datasets: datasetId.ToString(),
// reports: reportId,
// targetWorkspaces: groupId,
// allowEdit: true,
// accessLevel: "view";
}
但是,当我尝试使用 SSAS On Prem 执行此操作时,我收到消息“禁止”
Microsoft.Rest.HttpOperationException
HResult=0x80131500
Message=Operation returned an invalid status code 'Forbidden'
Source=Microsoft.PowerBI.Api
StackTrace:
at Microsoft.PowerBI.Api.ReportsOperations.<GenerateTokenInGroupWithHttpMessagesAsync>d__34.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.ReportsOperationsExtensions.<GenerateTokenInGroupAsync>d__95.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.ReportsOperationsExtensions.GenerateTokenInGroup(IReportsOperations operations, Guid groupId, Guid reportId, GenerateTokenRequest requestParameters)
at EmbedAPISample.Program.Main(String[] args) in C:\Users\USER\OneDrive\Documents\Projects\Power BI\Embed-API-Sample-master\Embed-API-Sample-master\EmbedAPISample\Program.cs:line 111
我已设置 Azure AD 应用程序注册,并且已授予其所有委派职责。
然后我将该主体名称添加到工作区以及我的网关中
我还映射了有效用户名,因此它将“user@Company.com”更改为“User@Staging.com”,因为 SSAS 中的角色使用 staging 作为其域。
相同的代码适用于同一工作区中的非 SSAS 数据集。
因此,在找到其他用户提供的故障排除链接后,我能够解决此问题。
一旦我最终将其添加到我的代码中,它就会解析出真正的错误消息:
Request: {
"accessLevel": "View",
"datasetId": "DATASET",
"identities": [
{
"username": "USER@COMPANY.com",
"datasets": [
"DATASET"
],
"roles": [
"Role"
]
}
]
}
Status: Forbidden (403)
Response: {"error":{"code":"InvalidRequest","message":"Creating embed token for accessing dataset DATASET requires gateway admin or datasource override effective identity access right"}}
RequestId: REQUESTID
然后我发现一篇文章指出,要将用户添加到网关作为管理员,您需要转到 Power Platform 管理中心 并在那里添加服务主体(或其用户组)。一旦我这样做了,一切就都成功了