Forum Discussion

pawels's avatar
pawels
New Member
6 years ago

Bearer generated on docs.microsoft.com works while oauth2 doesn't

Good day all,

 

I'm struggling for a while with generating Bearer for PBI REST API. Action that I'd like to make is to trigger truncating streaming data:

https://docs.microsoft.com/en-us/rest/api/power-bi/pushdatasets/datasets_deleterowsingroup

 

In order to do so I need to send DELETE message covered with bearer. When I'm using bearer generated in Try it section I've 200 OK answer - as expected.

 

I've registered app on dev.powerbi.com/apps for client id and secret with required scope Dataset.ReadWrite.All in order to generate bearer:

string resourceUri = "https://analysis.windows.net/powerbi/api";

string authorityUri = "https://login.windows.net/common/oauth2";

AuthenticationContext authContext = new AuthenticationContext(authorityUri);
string token = authContext.AcquireToken(resourceUri, new ClientCredential(clientID, clientSecret)).AccessToken;

 

Code above works and returns bearer, but once using it I've 401 UNAUTHORIZED. 

 

Question is: why bearer generated on Try it section (so on my credentials) works while bearer generated on app registration doesn't?

 

 

3 Replies