简体   繁体   English

Power BI - 以编程方式登录

[英]Power BI - Programmatically sign in

I'm trying to write a web app which embeds some Power BI reports.我正在尝试编写一个嵌入了一些 Power BI 报告的 Web 应用程序。 The data is on-premises so I cannot use the new solution available (Power BI Embedded).数据在本地,因此我无法使用可用的新解决方案(Power BI Embedded)。 Now the inconvenience of using the old approach ( https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-integrate-a-power-bi-tile-or-report/ ) is that the consumer of the web page needs to be a Power BI user which needs to sign in in order for the web app to finally get an authentication token (there is a couple of page redirections that need to happen before).现在使用旧方法( https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-integrate-a-power-bi-tile-or-report/ )的不便在于web 页面需要是 Power BI 用户,该用户需要登录才能让 Web 应用最终获得身份验证令牌(之前需要进行几次页面重定向)。 So my question is, is there a way to do the Power BI Sign In in a programmatic way?所以我的问题是,有没有办法以编程方式进行 Power BI 登录? so in that way I can just use one Power BI account for getting the content.这样我就可以只使用一个 Power BI 帐户来获取内容。

I am also experimenting there, this thread helped me with just that (see post #8):我也在那里进行实验,这个线程帮助我解决了这个问题(见帖子 #8):

http://community.powerbi.com/t5/Developer/How-to-use-Power-BI-Rest-API-without-GUI-authentication-redirect/mp/14218# http://community.powerbi.com/t5/Developer/How-to-use-Power-BI-Rest-API-without-GUI-authentication-redirect/mp/14218#

Basically:基本上:

POST request to: https://login.microsoftonline.com/common/oauth2/token POST 请求到: https : //login.microsoftonline.com/common/oauth2/token

Body, form-url-encoded:正文,表单 url 编码:

  • grant_type: "password" grant_type:“密码”
  • scope: "openid"范围:“openid”
  • resource: " https://analysis.windows.net/powerbi/api "资源:“ https://analysis.windows.net/powerbi/api
  • client_id: your client id client_id:您的客户 ID
  • client_secret: your client secret client_secret:您的客户机密
  • username: that username用户名:那个用户名
  • password: that usernames password密码:那个用户名密码

Then you directly get the token.然后你直接得到令牌。

Also it might be good to consider security concerns like described here: http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/ under "When NOT to Use This Feature"此外,考虑如下所述的安全问题可能会很好: http : //www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/在“When不要使用此功能”

It's just a coincidence that I am doing the same.我也在做同样的事情,这只是巧合。 Actually Power BI provides a Rest API to do this very easily.实际上,Power BI 提供了一个 Rest API 来很容易地做到这一点。 You need to register an app at Azure portal which will provide you with a client id and client secret.您需要在 Azure 门户注册一个应用程序,该应用程序将为您提供客户端 ID 和客户端机密。 Now you can use the rest API and these details.现在您可以使用其余 API 和这些详细信息。

POST: https://login.microsoftonline.com/common/oauth2/token

and in the body, you need to send these details and in the header, you need to set Content type : application/x-www-form-urlencoded在正文中,您需要发送这些详细信息,在标题中,您需要设置Content type : application/x-www-form-urlencoded

data: {
    grant_type: password
    scope: openid
    resource: https://analysis.windows.net/powerbi/api
    client_id: {Client ID}
    username: {PBI Account Username}
    password: {PBI Account Username}
    client_secret: {Enter client secret here}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM