Forum Discussion

PaulFowler's avatar
PaulFowler
Advocate I
10 years ago

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-Silently-with-Javascript-to/m-p/6580#M1178 

 

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

 

Thank you all.

7 Replies

  • 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's avatar
      PaulFowler
      Advocate I

      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

       

       

      • amikell's avatar
        amikell
        Helper I

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