Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 51346

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

$
0
0

Hi there,
I'm using the same flow as you mentioned here but I'm always getting error at that part.

If I use client credentials such as client_id then I get one token without any user consent dialog . (As long as I develop native java application I cant open a browser to pop it up.) Unfortunately I cant use this token to make a rest api call because I always get 403 forbidden. I understand that authentication for rest api calls should be user specific for Power Bi. So I use this example same as in the adal4f implementation and also with the post man rest tool.  I encounter same error in both as you see in the pictures.

 

{
  "error": "invalid_grant",
  "error_description": "AADSTS65001: The user or administrator has not consented to use the application with ID 'ef193d6d-5585-4286-bc7f-31eadd94446c'. Send an interactive authorization request for this user and resource.\r\nTrace ID: bd8c1e80-4965-4d85-b607-700505157055\r\nCorrelation ID: 9189059d-abea-4f30-8de1-321f25010dbd\r\nTimestamp: 2016-10-26 09:10:34Z",
  "error_codes": [
    65001
  ],
  "timestamp": "2016-10-26 09:10:34Z",
  "trace_id": "bd8c1e80-4965-4d85-b607-700505157055",
  "correlation_id": "9189059d-abea-4f30-8de1-321f25010dbd"
}

 

 private static void getPasswordCredentinal() throws IOException {
        HttpPost signIn = new HttpPost("https://login.windows.net/{mytenant}/oauth2/token");

        List<NameValuePair> nvps = new ArrayList<>();
        nvps.add(new BasicNameValuePair("grant_type","password"));
        nvps.add(new BasicNameValuePair("client_id","myId"));
        nvps.add(new BasicNameValuePair("resource","https://analysis.windows.net/powerbi/api"));
        nvps.add(new BasicNameValuePair("username","myuser"));
        nvps.add(new BasicNameValuePair("password","mypass"));
        nvps.add(new BasicNameValuePair("scope","openid")); //optinal
        signIn.setEntity(new UrlEncodedFormEntity(nvps));

        CloseableHttpClient client = HttpClients.custom().build();
        HttpResponse response = client.execute(signIn);
        System.out.println(response.getStatusLine().toString()+" "+response.getStatusLine().getReasonPhrase()+" "+response.getStatusLine().toString());
        String s = EntityUtils.toString(response.getEntity());
        JSONObject jsonObject=new JSONObject(s);
        accessToken = (String) jsonObject.opt("access_token");
        System.out.println(" json object >"+jsonObject);

    }

Both produce the same result. 

"error_description": "AADSTS65001: The user or administrator has not consented to use the application with ID 'ef193d6d-5585-4286-bc7f-31eadd94446c'. Send an interactive authorization request for this user and resource

So is there anyting I'm missing? Or is there any way to bypass this consent process programmatically?
Thanks for your help


Viewing all articles
Browse latest Browse all 51346

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>