Forum Discussion
PaulFowler
10 years agoAdvocate I
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 ou...
PaulFowler
10 years agoAdvocate 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.
- 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
amikell
10 years agoHelper I
Bump. Anyone have .js sample of obtaining an authorization code and access token for PowerBI?