cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PaulFowler Frequent Visitor
Frequent Visitor

How to get Power BI Access Token via Javascript?

I really don't understand how Microsoft and the PowerBI team provided javascript api examples for everything except how to get the access token...  I have been at this for a while trying to figure out how to get access to the api.  I have the client id for an app.  I don't want the users to have to sign in for themselves, I want to use my own microsoft id to get to my tile / dashboard to display on a web page.   Any thoughts?

 

Note the most relevant articles I found appear to be as follows:

 

Authenticate a client app (all .net examples)https://msdn.microsoft.com/en-US/library/dn877545.aspx 

Power BI API updates (gives javascript examples for everything but getting access token - which stinks!)http://blogs.msdn.com/b/powerbidev/archive/2015/09/23/power-bi-api-updates-roundup.aspx 

Integrate a Power BI tile into an apphttps://msdn.microsoft.com/en-US/library/mt450498.aspx 

Intro to creating a Power BI apphttps://msdn.microsoft.com/en-US/library/mt186546.aspx

Service to Service Calls Using Client Credentialshttps://msdn.microsoft.com/en-us/library/azure/dn645543.aspx 

 

And, of course, I am not the only person who wants to knowhttp://community.powerbi.com/t5/Integrations-with-Files-and/Example-Request-How-to-Authenticate-Sile...

 

So, how the heck to we do this so I can put a chart up on a web page?  

 

Thank you all.

7 REPLIES 7
diegomanule Frequent Visitor
Frequent Visitor

Re: How to get Power BI Access Token via Javascript?

Did you have any results?? Im right now with the same problem but trying to push data in some datasets regularly.

 

Couldn't find any examples nor routines to get a token with JS.

PaulFowler Frequent Visitor
Frequent Visitor

Re: How to get Power BI Access Token via Javascript?

Actually, we did.  This is a few months old, but here is what we found...

 

I am actually going to sharea complete set of findings related to putting PowerBI in an iFrame...  ADX Studio has the iFrame, but the answer to your question is buried here.

 

Connecting Power BI to ADX / CRM

Concepts:

  • When the CRM was created (or prior via Office 365), an Azure AD was populated behind the scenes with one or more organizational identities to sign onto CRM.
    • The CRM AD may have been combined with an Office 365 Azure AD (for single sign-on.)
    • The Azure AD should have identities of the organization and it is one of these identities we want to use for Power BI.
      • Preferably, we want a read-only identity for Power BI chart exposure.
      • All the C-Level staff need identities in or federated to this AD for Power BI.
    • Both CRM and ADX expose data via OData feeds.
      • CRM requires a validated identity to get to the OData feeds.
        • CRM is more "granular" with regards to the OData feeds, and as such, may be more difficult to navigate, requiring more knowledge of CRM.
      • ADX does NOT require a validated identity to get to the OData feeds.
        • This may be ideal for Open Gov initiatives.
        • Feeds have to still be created in ADX for each entity. This is not a security hole.

 

Registering ADX as a Power BI Application

Concepts:

  • oAuth 2.0 requires that the application authenticating, provide a client or web identity.
    • We register a client identity in Azure AD for ADX studio.
      • That identity will be used in javascript along with an anonymous user or "service account" to get access to PowerBI Dashboard Tiles.
      • To register a client identity, there must be access to Azure AD, which may not yet have been enabled.
        • We enable access via an Office 365 management screen that will set up an Azure Subscription with access to Azure AD.
        • We can get to the Office 365 management screen from the top left corner of Power BI, if we are confused.
      • We will need to save a "client id"
      • We will need to provide the application identity privileges to get to Power BI data

 

Authorizing ADX via oAuth 2.0 for Power BI

Concepts:

  • We use a part of the oAuth 2.0 standard which is supported by Microsoft Azure AD, but is not described in documentation for accessing PowerBI.
    • Lucky, we knew the standard in enough detail to make this work J
    • We use what is known as a "Password Grant" which requires 4 items to get access:
      1. client_id=Client ID from registration in last section.
      2. username=anonymous user's username
      3. password=anonymous user's password
      4. resource=https://analysis.windows.net/powerbi/api
        • ok, figuring out that resource was friggin hard as hell!!! It is unadvertised by Microsoft, and frankly it could be a risk in the future although the likelihood is low.
  • TODO: figure out best method to secure password, etc. Site Settings are one possible method.
  • We will get an "Access Token" that is sent with every request to Power BI

Discovering Tiles

  • Each "Tile" or chart on the Dashboard has an embed url that can be used in an iFrame.
    • That URL is only currently visible via an API call.
    • TODO: create a non-developer method of finding urls for Tiles

Putting Tiles In an iFrame

  • An iFrame is a part of the window that can contain we page
    • There is javascript that will contact the PowerBI API and display a "Tile" or chart in an iFrame.
    • ADX studio makes the development of javascript and the specification of an iFrame fairly easy.
      • TODO: The challenge is creating a method for non-developers

 

 

junallan Frequent Visitor
Frequent Visitor

Re: How to get Power BI Access Token via Javascript?

Hi, how did you pass the username and password for OAuth?  I want to do the same in SharePoint, but I'm confused as how to get at the profile password?  Thanks.

amikell Regular Visitor
Regular Visitor

Re: How to get Power BI Access Token via Javascript?

Bump. Anyone have .js sample of obtaining an authorization code and access token for PowerBI?

ronnoc Regular Visitor
Regular Visitor

Re: How to get Power BI Access Token via Javascript?

I am also lost with trying to find the access token.

ronnoc Regular Visitor
Regular Visitor

Re: How to get Power BI Access Token via Javascript?

Any updates on how to get a hold of the access token???

Steve_Wheeler Established Member
Established Member

Re: How to get Power BI Access Token via Javascript?

My understanding is that, unless it is provided as a specific Connector in Power Query (e.g. Facebook, SharePoint Online List maybe), Power BI doesn't currently support the full callback process for user-id/password authentication per oAuth2.  Per http://angryanalyticsblog.azurewebsites.net/index.php/2016/05/16/api-strategies-with-power-bi/, "Power BI cannot read a response returned to a callback URL and if the API you are using requires that “authentication flow” then it can’t be used with Power BI (well, that is not entirely true, but to prevent this blog from being 50 pages long, we will say it can’t). For instance, the LinkedIn API requires this flow so it is not something we can connect to from Power BI easily."

 

It WILL work for an application-level token per that link showing access via public Twitter Search API.

 

To help get this service improved, consider voting for an (the best?) oAuth idea at https://ideas.powerbi.com/search?filter=ideas&query=oauth

 

 

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 55 members 1,137 guests
Please welcome our newest community members: