Forum Discussion
How to use Power BI Rest API without GUI authentication (redirect uri)
- 10 years ago
You can use the user name and password flow that AAD supports. This 3rd party client library has an example: https://github.com/Vtek/PowerBI.Api.Client
Shaun,
There are a couple steps needed to silently authenticate.
1. You need to manually log in with the account once because PowerBI will prompt you with permissions. Once you've accepted, the account can be set up for silent authentication.
2. In c#, aquire the token like this
// Create an instance of TokenCache to cache the access token TokenCache TC = new TokenCache(); // Create an instance of AuthenticationContext to acquire an Azure access token authContext = new AuthenticationContext(authority, TC); string resourceUri = "https://analysis.windows.net/powerbi/api"; string clientID = "your client id here"; string email = "your email here"; string password = "your password here"; // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint token = authContext.AcquireToken(resourceUri, clientID, email, password).AccessToken;
If you perform these steps properly, you can do whatever you want in the background. I have this in an executable file that's triggered by my database any time there is new data that I want to push out to a PBI dataset.
I have largely followed the following post in our integration.
https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-get-azuread-access-token/
Do the steps you detail above to achieve silent Powerbi login also apply if our architecture falls into the
Access token for Power BI users (user owns data)
category from the article link I posted ?
Ours is an an application written and distrubuted to our clients who all have their own Powerbi pro accounts and content.
We are just wanting a way they can consume their content within our application and not have to log in each and every time.
Big thanks in advance for your previous post and any response
- heitzmanjared8 years agoFrequent Visitor
If that's the case I think you'll probably need them to login every time. The access token expires so you'll need their password each time even if you want to silently authenticate.
- shaunwilks8 years agoHelper V
If we were storing their username and password in our application then can we pass it silently each time to log them in silently rather than having them be redirected to a website to have them login each and every time ?
I just see no point in the API in this particular instance especially for non web based interfaces.
Here is an API that you can invoke to consume Powerbi content
BUT
everytime you wish to consume it we need to redirect you to a website to login and then then come back to the non webbased interface to consume it
The user experience is better if you have a link to the Report URL inside an iframe because at least after you log in there you have the remember me option that doesnt prompt you again for a long period of time.
But use the API and we are forced to have them jump from a non web ui, into a web ui and then back to the non web ui.
- heitzmanjared8 years agoFrequent Visitor
Technically speaking, you could store their usernames/passwords and achieve the silent authentication that you desire. But I would strongly discourage doing that. Storing passwords is almost never a good idea.
You should look around and see if there is any way to grab the logged in user's windows credentials, and pass that to the acquireToken method instead of the username and password strings. I would imagine that there is a simple way to do that.