Microsoft Graph APIを使用してOffice 365アカウントにアクセスする際に問題が発生しました。グラフ365経由のOffice 365アクセス
最初の問題は、Office 365サブスクリプションのすべてのユーザーを一覧表示しようとしているJavaプログラムがあることです。 https://graph.microsoft.com/v1.0/users/
に電話していますが、403 forbidden
が返ってきています。
アプリの登録時に、私はUser.Read
、User.ReadBasic.All
、User.ReadWrite
などの権限を委任された権限とアプリの権限の両方に追加しました。
私もグラフエクスプローラを使用しようとしましたが、アカウントを使用するために入力すると、まだグラフの組み込みユーザーが使用され、アプリケーションのログイン情報は表示されません。これらが関連しているかどうかは不明です。ここで
は403AuthenticationResult result = getAccessTokenFromUserCredentials(RESOURCE_GRAPH, ID, PASSWORD);
URL url = new URL("https://graph.microsoft.com/v1.0/users/") ;
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Bearer "+result.getAccessToken());
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
、その結果、コードスニペットであり、ここでapps.dev.microsoft.comで扱うにトークン
private static AuthenticationResult getAccessTokenFromUserCredentials(String resource,
String username, String password) throws Exception {
AuthenticationContext context;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
resource, CLIENT_ID, username, password,
null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException(
"authentication result was null");
}
return result;
}
あなたは '/ users'に渡すトークンを取得するためにユーザーを認証していますか? –
コード例で更新しました。 https://graph.microsoft.com/v1.0/me/を呼び出すと、私のユーザーを表すjson文字列が返されます。しかし、私は/ users /と呼ぶと403を取得します。私はsharepointエンドポイントokにアクセスしてサイトデータなどを取得することもできます。 – Gary
User.ReadBasic.Allは管理者の同意が必要です、管理者の同意を得ようとしましたか?あなたはどこにアプリを登録しますか? –