guyinacube / Embed-API-Sample

A sample application to use the Power BI APIs for embedding. This makes use of the Power BI .NET SDK which in turn calls the Power BI REST API.
GNU General Public License v3.0
22 stars 22 forks source link

Invalid status code 'Forbidden' #2

Open lamnv5490 opened 7 years ago

lamnv5490 commented 7 years ago

Hi sir, I have run your sample then i got stucked in 2 case:

  1. I changed clientId, username, password then I got The request body must contain the following parameter: 'client_secret or client_assertion.
  2. After some researched I found that I should use var clientCre = new ClientCredential(clientId, clientSecret); This case I already got token. But then got stuck again in using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials)) { var groups = client.Groups.GetGroups(); }. It said Microsoft.Rest.HttpOperationException: 'Operation returned an invalid status code 'Forbidden''.

I wonder that this sample is for Native ?

ankit-h commented 7 years ago

@lamnv5490 I got the same error!

aminebizid commented 6 years ago

Same error here, I get Forbidden. Why they don't use the same auth metod as for PBI Collections?

lamnv5490 commented 6 years ago

@aminebizid You should try Native App and dont forget to grant permission on AAD. if you try .NET Core. You will need to use REST API to get token, they just dont support .NET Core 2.0

aminebizid commented 6 years ago

@lamnv5490 I added PowerBi Service as required Permission on the principal. Do I need another permessions to make it work?

_clientCredential = new ClientCredential(myClientId, myClientSecret);

authenticationResult = await _authContext.AcquireTokenAsync("https://analysis.windows.net/powerbi/api", _clientCredential);

_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Bearer, _authenticationResult.AccessToken);

var resp = await _httpClient.GetAsync("https://api.powerbi.com/v1.0/myorg/groups");

I get 401

lamnv5490 commented 6 years ago

Have you click "Grant Permission"? I missed it once.