簡體   English   中英

使用Graph API進行Azure AD導入適用於隨機應用程序

[英]Azure AD Import using Graph API works for random applications

我正在使用Graph API從Azure AD導入用戶。 在我的活動目錄中,我正在配置此鏈接后的應用程序。

在我的代碼中,我生成一個accessstoken並傳遞該訪問令牌以獲取用戶列表。

//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”:{“code”:“Authorization_RequestDenied”,“message”:{“lang”:“en”,“value”:“沒有足夠的權限來完成操作。” }}}

一旦你點擊“授予權限”按鈕,更改需要時間(可能超過10分鍾),你可以等待那段時間,然后再試一次 - 問題是否仍然存在?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM