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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
seijim
Employee
Employee

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

I'm developing an Azure worker role application which pushes data to PowerBI.com 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.

 

Thanks,

-Seiji

1 ACCEPTED SOLUTION
jocaplan-MSFT
Employee
Employee

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

View solution in original post

53 REPLIES 53

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 : aka.ms/practicalDAX

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 : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi,

 

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 : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi,

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..

 

Regards,

Vish.

jocaplan-MSFT
Employee
Employee

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

aevers
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 ?

 

Regards,

-seiji

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.