gpt4 book ai didi

Azure Active Directory Sharepoint 和 Graph API

转载 作者:行者123 更新时间:2023-12-03 01:07:00 26 4
gpt4 key购买 nike

我对如何获取适用于共享点网站以及图形 API 的不记名 token 感到有点困惑。

我们正在使用 MFA(多重身份验证),因此当用户尝试登录时我们会收到一条短信。这一切都有效,我们得到了一个 token ,但我指向的资源是 https://srmukdev.sharepoint.com/ ,我们如何使用这个 token 来访问 https://graph.microsoft.com/ API。

目前还不起作用。我可以发出单独的登录请求,但我们不想这样做,因为需要使用相同的 token 访问这两个部分?有没有一种方法可以将一个 token 转换为另一个 token ?至少有用的东西?

可以看到当前的区别是ResourceUrl

我使用的 sharepoint api 详细信息

<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:Tenant" value="srmukdev.onmicrosoft.com" />
<add key="ida:ApplicationId" value="000000-0000-0000-0000-0000000" />
<add key="ida:RedirectUri" value="http://someuri/" />
<add key="ida.ResourceUrl" value="https://srmukdev.sharepoint.com/" />

我使用的图表 API 详细信息

<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:Tenant" value="srmukdev.onmicrosoft.com" />
<add key="ida:ApplicationId" value="000000-0000-0000-0000-0000000" />
<add key="ida:RedirectUri" value="http://someuri/" />
<add key="ida.ResourceUrl" value="https://graph.microsoft.com/" />

非常感谢

最佳答案

首先我们要说的是,您无法获取直接适用于 Microsoft Graph API 和 SharePoint API 的 token 。 token 是针对特定受众创建的,作为 Web API token 验证的一部分,他们将检查 token 的受众是否与其唯一标识符相匹配。

我认为一种可能的解决方案是认识到 Microsoft Graph token 已允许您访问 SharePoint API。请参阅documentation here 。您应该能够仅获取 Microsoft Graph 的 token ,然后使用 Microsoft Graph 特定终结点从 SharePoint 获取数据。这是 Microsoft Graph 试图解决的问题之一。用于访问所有 Microsoft 数据的单个端点和 token 。

另一个解决方案是使用您收到的授权代码向两个不同的端点请求两个 token 。根据您使用的库以及您遵循的具体流程,这可能比不完成更困难,但一般来说,authorization code grant flow用于登录用户。用户重定向到 Microsoft 登录页面并成功登录后,您的服务会收到授权代码,然后使用 token 终结点将其交换为访问 token 。此授权代码可用于获取客户端已配置为调用的任何资源的访问 token ,因此您可以使用两个不同的资源值调用 token 端点两次,并取回两个访问 token 。我在我的 Python/Flask samples 之一中执行此操作.

最后,假设您获得了特定资源的访问 token 和刷新 token ,则您可以使用刷新 token 来获取应用程序已授权的不同资源的 token 。

The refresh token issued by Azure AD can be used to access multiple resources. For example, if you have a client application that has permission to call two web APIs, the refresh token can be used to get an access token to the other web API as well.

参见here了解如何执行此操作。

关于Azure Active Directory Sharepoint 和 Graph API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45544892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com