Azure Active Directory 图 Api - 用户

Azure Active Directory Graph Api - Users

我正在尝试使用图表 API,我正在对 SharePoint 网站作为资源进行身份验证 URL。这是因为我正在使用 C# CSOM api 与共享点站点交谈。

当我尝试使用相同的不记名令牌发出图形 api 请求时,它说未授权。我也给了移动应用程序 Graph API 的权限。这是否意味着我的资源 uri 需要不同,如果是这样,它应该是什么,因为它不清楚?我不确定如何找到它。

我基本上想在 azure 中授予已注册的应用程序共享点和图形的权限 api。当我获得令牌时,我希望能够将其用于两种类型的请求

var client = new HttpClient();

client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "TOKEN_FROM_AUTHENTCIATION");

var result = client.GetAsync("https://graph.microsoft.com/v1.0/me/messages?$select=subject,from,receivedDateTime&$top=25&$orderby=receivedDateTime%20DESC").Result;

我的连接详细信息类似于以下内容:

<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:Tenant" value="mytenant.onmicrosoft.com" />
<add key="ida:ApplicationId" value="A GUID" />
<add key="ida:RedirectUri" value="http://AnyUri/" />
<add key="ida.ResourceUrl" value="https://mytenant.sharepoint.com/" />

我在想我的 ResourceUrl 需要是一个图表 api 但无法理解它应该是什么,我是否必须创建图表的实例api 我的域?

我正在使用 fiddler 使用令牌发出此请求,如下所示,但这返回为未经授权的 401

GET https://graph.windows.net/22312560-20c8-0000-0000-0000000000/users/user@microsoft.com/$links/manager?api-version=1.6

Content-Type: text/json
Accept: application/json
Host: graph.windows.net
Content-Length: 0
Authorization: Bearer <THE_TOKEN>

以下是您需要遵循的步骤,以确保您的应用按预期运行:

  1. 确保您的应用注册 permissions to the Microsoft Graph 具有进行 API 调用所需的范围。

  2. 将您的资源设置为“https://graph.microsoft.com/

  3. 获取此资源的 new access token
  4. 使用这个新令牌调用 Microsoft Graph API。您可以使用像 this one.
  5. 这样的 JWT 解码器来检查一切是否正常