Forum Discussion
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.
- CRM requires a validated identity to get to the OData feeds.
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
- We register a client identity in Azure AD for ADX studio.
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:
- client_id=Client ID from registration in last section.
- username=anonymous user's username
- password=anonymous user's password
- 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
Bump. Anyone have .js sample of obtaining an authorization code and access token for PowerBI?
- ronnoc9 years agoAdvocate II
I am also lost with trying to find the access token.
- ronnoc9 years agoAdvocate II
Any updates on how to get a hold of the access token???
- Anonymous9 years agoNot applicable
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