PowerBi-嵌入式 - 未经授权
我一直在尝试不运气,以获取嵌入令牌,以便能够将我的PowerBi报告嵌入我现有的.NETCORE WEB API应用程序中。前端看起来像是Power BI为我准备的超级简单1个简单的反应组件。
但是对于后端来说,我实际上是在圈子。
我到了我决定这样做的最干净的方法是通过HTTP触发功能。
(请参阅此信息: https> https:https:// www。 taygan.co/blog/2018/05/14/embedded-analytics-with-power-bi )
是一个重要的旁注:我确实已经授予了我的申请API)
另一个旁注是,我试图做主用户,应用程序拥有数据方法
另一个旁注是,您会看到上面的链接,代码显示您使用Microsoft不再支持(似乎是)的方法获得AAD auth
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.PowerBI.Api;
using Microsoft.PowerBI.Api.Models;
using Microsoft.Rest;
using Newtonsoft.Json;
namespace PowerBiExample
{
public class EmbedContent
{
public string EmbedToken { get; set; }
public string EmbedUrl { get; set; }
public string ReportId { get; set; }
}
public static class Test
{
private static string tenantId = "this is the id of my entire organization";
static string authorityUrl = $"https://login.microsoftonline.com/{tenantId}";
static string resourceUrl = "https://analysis.windows.net/powerbi/api";
static string apiUrl = "https://api.powerbi.com/";
private static string clientId = "this is the client id of my application that i gave delegate permissions to";
private static string clientSecret = "this is the secret of the application i gave delegate permissions to";
private static string username = "ad master user that i WANTED to sign into power bi with";
private static string password = "that ad users pw";
private static Guid groupId = Guid.Parse("workspaceid in powerbi");
private static Guid reportId = Guid.Parse("report id from within that workspace");
[FunctionName("Test")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
var credential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authorityUrl);
// var authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, clientId, credential);
var authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, credential);
string accessToken = authenticationResult.AccessToken;
var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
{
// Embed URL
Report report = client.Reports.GetReportInGroup(groupId, reportId);
string embedUrl = report.EmbedUrl;
// Embed Token
var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
EmbedToken embedToken = client.Reports.GenerateTokenInGroup(groupId, reportId, generateTokenRequestParameters);
// JSON Response
EmbedContent data = new EmbedContent();
data.EmbedToken = embedToken.Token;
data.EmbedUrl = embedUrl;
data.ReportId = reportId.ToString();
var s = JsonConvert.SerializeObject(data);
return new JsonResult(s);
// JavaScriptSerializer js = new JavaScriptSerializer();
// string jsonp = "callback(" + js.Serialize(data) + ");";
//
// // Return Response
// return new HttpResponseMessage(HttpStatusCode.OK)
// {
// Content = new StringContent(jsonp, Encoding.UTF8, "application/json")
// };
}
}
}
}
令牌。我没有返回嵌入令牌。我对此感到未经授权。
也很重要的说明:1。我也没有像在这里启用服务校长那样在这里学习。microsoft.com/en-us/power-bi/enterprise/ (我的该部门说我不能)。和2。它们不是工作空间上的管理员或成员,但是当我尝试将其添加为成员时,它们就不可用。这是一个应用程序,而不是用户或组。我该怎么办
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查以下几点是否可以让您有一个工作。
注册申请可能缺少许可范围
在Azure AD中。
验证所需的范围
存在于Azure Portal ex中的Azure AD的应用程序注册:OpenID,
配置文件,离线等,具体取决于要求和用户
登录。
Azure门户。
门户管理员 。
并获取Azure广告令牌。主用户需要具有 功率
Bi Pro 或 每用户(ppu)许可。
生成
仔细,并提供适当的许可。
因此,如果您使用相同的Azure AD令牌来生成几个嵌入令牌,则每个调用 将较短。
有时,这可能是由于嵌入代币到期而导致未经授权错误的原因,
MicrosoftDocs/Powerbi-Docs·Github 查看几个问题,
在您的情况下查找主要问题。
And also check if you need to provide datasetId
Some references:
分析应用程序 - Power BI | Microsoft Docs
应用-Power BI |微软文档
Please check if below points can give an idea to work around.
permission scope may be missing for the registered application
within Azure AD.
Verify the required scope
is present within theapp registration for Azure AD within the Azure portal ex: openid ,
profile, offline etc depending on the requirement and the user
logged in.
Azure portal.
gateway admin.
and get the Azure AD token. The master user needs to have a Power
BI Pro or a Premium Per User (PPU) license.
generate an embed token to allow its users to access specific
Power BI content.
carefully and give proper permissions.
Therefore, if you use the same Azure AD token to generate several embed tokens, the lifetime of the generated embed tokens will be shorter with each call.
Sometimes that can be the reason for the unauthorized error due to expiry of embed token
MicrosoftDocs/powerbi-docs · GitHub to see several issues and
find what is the main issue in your case.
And also check if you need to provide datasetId
Some references:
API call using Service Principal - Stack Overflow
analytics application - Power BI | Microsoft Docs
application - Power BI | Microsoft Docs