Microsoft Graphタスクを操作するためにMicrosoft 365 Office Plannerと対話するデーモンアプリを開発しています。テナントに関連するタスクを取得するためにMicrosoft Graph APIを呼び出すと、Unauthorizedリクエスト例外が発生します。テナントにアクセスデーモンアプリケーションからMicrosoft Graph
私はAzure Active Directoryに自分のアプリケーションを登録し、Microsoft Graphを使用する権限も与えました。
私はここからのプロセスに基づいてアクセストークンを要求: https://graph.microsoft.io/en-us/docs/authorization/app_only
私はAzureのActive Directoryのバージョン2.0のエンドポイントからトークンを取得することができています。 要求コードは以下の通りです:
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("client_id", "<clent id>"),
new KeyValuePair<string, string>("client_secret", "<client secret>"),
new KeyValuePair<string, string>("resource", @"https://graph.microsoft.com")
var content = new FormUrlEncodedContent(pairs);
var response = client.PostAsync("https://login.microsoftonline.com/<tenant id>/oauth2/token", content).Result;
私は次のようにリクエストを実行するには、このアクセストークンを使用します。
: client.DefaultRequestHeaders.Authorization= new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var response = client.GetAsync(@"https://graph.microsoft.com/beta/tasks").Result;
私は、次の応答メッセージで不正なステータスコード401を取得します
Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
私のアプリへのアクセスを許可するために実行しなかった承認プロセスはありますか?助けてください!!!!
ありがとうございます!