在Azure Active Directory中使用MS Graph API:C#和邮递员

问题描述 投票:0回答:1

我是MS Graph API的新手,并试图使用在Azure AD中注册的MS Graph检索SharePoint列表项。我能够通过传递以下参数(client_id,client_secret,资源,授权)来检索访问令牌,因此问题出在运行api url时:邮递员https://graph.microsoft.com/v1.0/sites/{{site-id}}/lists/{{list-id}}/items?$Select=Id&$expand=fields($select=Title)(通过在Header中传递Bearer-access令牌)。

我收到以下错误消息,指出“ 令牌中必须包含scp或角色声明”。如果您能指导我提供正确的解决方案,因为我正在尝试使用api,那将是非常不错的选择使用C#并收到以下错误,指出“ 403-Forbidden

using (var client = new HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/sites/{{site-id}}/lists");
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
var response = client.SendAsync(request).Result;


//var result = requestTask.Result;
if (response.IsSuccessStatusCode)
{
  var readTask = response.Content.ReadAsStringAsync();
  readTask.Wait();
  Console.WriteLine("Response:" + readTask);
}

}
azure azure-active-directory azure-ad-graph-api
1个回答
0
投票

[在list中获得项目集合时,需要具有以下权限。

enter image description here

并且根据您提供的pictureSites.Read.AllSites.ReadWrite.All的应用程序权限未授予同意,因此显示黄色警告。正确的状态如下:

enter image description here

您需要授予管理员对这些权限的同意,然后对访问令牌进行解码,您将在role声明中看到该应用程序的权限。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.