Skip to main content
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started


How to use Power BI Rest API without GUI authentication (redirect uri)

I'm developing an Azure worker role application which pushes data to service.

I referred a C# sample client application via Git Hub. But it authenticates using GUI (redirect uri) during the below step.

>> token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken.ToString();


I need a sample code without GUI (redirect uri) authentication which means silent mode authentication.





You can use the user name and password flow that AAD supports. This 3rd party client library has an example:

View solution in original post


So in my case, when I log into Power BI using our company SSO, I use the my internal company AD network username and password. 


Are you saying these should work ok?


Oh and I take it your code is designed to work with a Web app?  I'm trying to use and SSIS script task to push rows up to a Dataset\table.

To learn more about DAX visit :

Proud to be a Datanaut!

The big catch is that you have to give permissions the first time. In my case, the account that "owns" the dataset is my personal account. I had to set up my app to use traditional authentication wiht a redirect, and go through the typical permisson acceptance to let PowerBI know that I approve the permissions I identified when registering the app. Once i did that, I was able to use my username and password and make an automatic call every 30 minutes with no user intervention. If this isn't clear, please let me know and we can have a quick call to clarify

I keep getting a 400 error "Bad Request".  I'm not entirely sure I'm using the correct values for the TenantID, username/password etc.


I ripped the TenantID out of the page source of Power BI HTML page after logging in. 


I've tried a few combinations but allways seem to get the 400 error.  


Very frustrating.

To learn more about DAX visit :

Proud to be a Datanaut!



I get the same error "Bad Request" . I think my TenantID, user and password are correct but always get the same error, I try different combinations "/oauth2/v2.0/token" "/oauth2/token/" but not work.


Currently is valid this way of access or there have to access by power bi embedded?

I can handle that for now.  


I take it you used a web-app rather than the native-app given there is a client-secret in your code.

To learn more about DAX visit :

Proud to be a Datanaut!


I am bit confused as to where I can call this code for test. I am new to C#  and it may be the reason for confusion. However I went thru some sample codes in sample application embed-a-tile-into-an-app (Github -dvana/PowerBI-CSharp) etc..  Any chance you could explain some dtails on how to use this code etc..





You can use the user name and password flow that AAD supports. This 3rd party client library has an example:

Advocate I
Advocate I

I did this by using the refresh token provided by the GUI authentication process and only using the AcquireTokenByRefreshToken method in my worker with the this token. I now just have to refresh the RefreshToken after a few days and update the configuration of my cloud worker (stored in redis -> worker checks for updated token). I do not re-use the Refresh Token in the configuration for every authentication request though but the new ones provided by AcquireTokenByRefreshToken.

@aevers what you say makes sense, but how do you refresh the token after a few days? Have you automated this?


My app doesn't use Active Directory so I will want a single account setup and to silently authenticate to display the report to a certain set of users.


I was thinking that the Active Directory REST api might be another option, but I've not used it before and just reading into it.

Thanks for your suggestion.

I will try it.

Did the suggestion provided by him worked for you. Because i feel the suggestion provided is not relavant to the one you asked. He mentioned as  "using the refresh token provided by the GUI authentication process" but as per my understanding its not the question you asked. I guess asked not to redirect to the loginpage, instead it should authenticate silent through code and get the "code" parameter in turn.

Thanks for your message.

Actually his answer doesn't completely adapt to my requirement in the point of GUI less.

But that's an useful workaroound. 


Azure Stream Analytics (ASA) also requires Web GUI authentication on management portal when we select Power BI output.

I've been thinking that his workaround is an only solution because ASA behaves so. 


Do you know how to implement silent authentication ?





Helpful resources

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.