This example shows how to get an access token for a Power BI client application when using the Basic Authentication grant type.
Required information
-
Token URL - https://<hostname>/api/Authentication.asmx/Authenticate
Here, the hostname for the identity provider is the same as that for Smart Completions because the basic authentication grant type is only supported for Power BI when using the Smart Completions Authentication identity provider. When using other identity providers, the hostname for the Identity provider will be different than the hostname for Smart Completions.
-
Your Smart Completions username and Password
Create a query to get an access token
Be extremely cautious about sharing PBIX templates! The credentials stored in the token function will allow anyone to access data, including data stored in other applications and shared with Smart Completions.
-
In the Power BI desktop tool, create a blank query.
-
Right-click the query, and select Advance Editor.
-
Copy and paste the following code into the blank query:
()=>let
url ="https://<hostname>/api/Authentication.asmx/Authenticate",
headers = [#"Content-Type" = "application/json"],
postData = Json.FromValue([
providerURL = "<hostname>",
UserName = "joe",
Password = "joe123",
ip= "0.0.0.1",
isMobile= 0]
),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),
Data = Json.Document(response),
access_token=Data[d][AuthToken]
in
access_token
-
Replace <hostname> (for url and providerURL), UserName , and Password with your information.
-
Change the query name to GetToken, and select Done.
Use the query to get the access token
-
Create a second blank query for getting the token using the above GetToken function.
-
Copy and paste the following code into the blank query:
let
Source=OData.Feed("https://<hostname>/sc/datalake/v1",
[Authorization="Bearer "&GetToken()],[MoreColumns=true])
in
Source
-
Replace the <hostname> placeholder with your hostname.
-
Select Done.
The query automatically generates a token and loads the data.