简体   繁体   中英

Power BI - Programmatically sign in

I'm trying to write a web app which embeds some Power BI reports. The data is on-premises so I cannot use the new solution available (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). So my question is, is there a way to do the Power BI Sign In in a programmatic way? so in that way I can just use one Power BI account for getting the content.

I am also experimenting there, this thread helped me with just that (see post #8):

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

Body, form-url-encoded:

  • grant_type: "password"
  • scope: "openid"
  • resource: " https://analysis.windows.net/powerbi/api "
  • client_id: your client id
  • client_secret: your 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"

It's just a coincidence that I am doing the same. Actually Power BI provides a Rest API to do this very easily. You need to register an app at Azure portal which will provide you with a client id and client secret. Now you can use the rest API and these details.

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

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}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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