none
Trying to get access token for power bi client getting unauthorized

    Question

  •  using (HttpClient client = new HttpClient())
                {
                    var tokenEndpoint = @"https://login.microsoftonline.com/c76b2843-f664-4aea-b02e-5b8c4e69e69d/oauth2/token";
                    var accept = "application/json";
                    client.DefaultRequestHeaders.Add("Accept", accept);
                    string postBody = @"resource=https://analysis.windows.net/powerbi/api
                                    &client_id=dbfcd775-c0f0-4058-b556-45dc8f47bc55
                                    &client_secret=xrkf61T3nUz6WsqWf0Q1XYq+B1R3UblWHpL0XW6Of84=
                                    & grant_type=password
                                    &username=sudheerM@TODASSS.onmicrosoft.com
                                    &password=<password>
                                    &scope=openid";

                    using (var response = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded")))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var jsonresult = JObject.Parse(await response.Content.ReadAsStringAsync());
                            var stoken = (string)jsonresult["access_token"];
                        }
                    }
                }
    Thursday, January 10, 2019 3:20 PM

All replies

  • I believe you are getting this error as the username/password which you are passing does not have access to Power BI. Please make sure that you are passing the PowerBI Credentials (Account User Name and Password) to REST API end point.
    Saturday, January 12, 2019 12:17 AM
    Moderator