2017-02-17 34 views
1

我正在使用图形API从Azure AD导入用户。在我的活动目录中,我正在配置这个link之后的应用程序。使用图形API的Azure AD导入适用于随机应用程序

在我的代码中,我生成一个accesstoken并传递该访问令牌以获取用户列表。

//get token 

      String secretKey = EncryptionUtils.decryptAES(encodedSecretKey); 
      secretKey = URLEncoder.encode(secretKey); 
      String urltoConnect = loginUrlPrefix+tenantId+loginUrlSufix; 
      String payLoad = "resource=https%3A%2F%2Fmanagement.core.windows.net%2F&client_id="+clientId+"&grant_type=client_credentials&client_secret=" + secretKey; 
      System.out.println(payLoad); 
      URL url = new URL(urltoConnect); 
      URLConnection connection = null; 
      connection = url.openConnection(); 
      connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
      connection.setDoOutput(true); 
      java.io.OutputStreamWriter wr = new java.io.OutputStreamWriter(connection.getOutputStream()); 
      wr.write(payLoad); 
      wr.flush(); 
      BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); 
      String content; 
      String html = ""; 
      while ((content = br.readLine()) != null) { 
       if (!content.equals("") && content.length() != 0) 
        html += content.trim(); 
      } 
      return html; 


//get user list 

      URL url = new URL(String.format("https://graph.windows.net/%s/users?api-version=2013-04-05", tenant, 
        accessToken)); 

      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
      // Set the appropriate header fields in the request header. 
      conn.setRequestProperty("api-version", "2013-04-05"); 
      conn.setRequestProperty("Authorization","Bearer "+ accessToken); 
      conn.setRequestProperty("Accept", "application/json;odata=minimalmetadata"); 
      String goodRespStr = HttpClientHelper.getResponseStringFromConn(conn, true); 
      int responseCode = conn.getResponseCode(); 
      org.json.JSONObject response = HttpClientHelper.processGoodRespStr(responseCode, goodRespStr); 
      org.json.JSONArray users; 

      users = JSONHelper.fetchDirectoryObjectJSONArray(response); 

如果我添加它适用于少数多个应用程序给出了这样的错误休息

{ “odata.error”:{ “代码”: “Authorization_RequestDenied”, “消息”:{ “lang”:“en”, “value”:“没有足够的权限来完成操作。” }}}

回答

0

一旦你点击“授予权限”按钮,改变需要时间(可能还有超过10分钟)得到应用,你可以等待的时间量,然后再次尝试 - 做的问题依然存在?

相关问题