2

I got the Authorization token from PowerBi, and while requesting dataset, I receive 403 error. I can verify that this work with Apiary and return result. It is a windows Form Application. My code set is as below

 string clientID = "{My App Client ID}";
 string redirectUri = "https://login.live.com/oauth20_desktop.srf";
 string resourceUri = "https://analysis.windows.net/powerbi/api";
 string authorityUri = "https://login.microsoftonline.com/{MyID}/oauth2/token";
 AuthenticationContext authContext = new   AuthenticationContext(authorityUri);
 AuthenticationResult result = null;
 ClientCredential cc = new ClientCredential(clientID, "{secret}");
 result = await authContext.AcquireTokenAsync(resourceUri, cc);
 token = result.AccessToken;

 string powerBIApiUrl =  "https://api.powerbi.com/v1.0/myorg/datasets";
 HttpWebRequest request = System.Net.WebRequest.Create(powerBIApiUrl) as     System.Net.HttpWebRequest;
 request.KeepAlive = true;
 request.Method = "GET";
 request.ContentLength = 0;
 request.ContentType = "application/json";
 request.Headers.Add("Authorization", String.Format("Bearer {0}", token));
  using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
  {
    using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
    {
       string responseContent = reader.ReadToEnd();
       JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
       Datasets datasets = (Datasets)JsonConvert.DeserializeObject(responseContent, typeof(Datasets));
       return datasets.value;
     }
   }
  • If you use 2.12 version of AD dll and use ` authContext = new AuthenticationContext(authority, TC); // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri), PromptBehavior.RefreshSession).AccessToken; ` it works perfectly fine. since this is no longer supported in latest version of AD, can't find a replacement method for this. – Sudheesh PM Feb 01 '17 at 06:11

0 Answers0