Azure 活动目录 Sharepoint 和图表 API
Azure Active directory Sharepoint & Graph API
我有点困惑如何获得适用于共享点网站以及图表的不记名令牌 api。
我们正在使用 MFA(多因素身份验证),因此当用户尝试登录时我们会收到一条短信。这一切都有效,我们得到了一个令牌,但我指向的资源是 https://srmukdev.sharepoint.com/, how can we use this token to access the https://graph.microsoft.com/ api。
目前它不起作用。我可以提出单独的登录请求,但我们不想这样做,因为它需要使用相同的令牌访问两个部分?有没有一种方法可以将一个标记转换为另一个标记?至少有用的东西?
可以看到当前不同的是ResourceUrl
我使用的分享点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 的令牌。令牌是针对特定受众创建的,作为 Web API 令牌验证的一部分,他们将检查令牌的受众是否与其唯一标识符匹配。
我认为一种可能的解决方案是认识到 Microsoft Graph 令牌已经允许您访问 SharePoint API。参见documentation here。您应该能够仅获取 Microsoft Graph 的令牌,然后使用 Microsoft Graph 特定端点从您的 SharePoint 获取数据。这是 Microsoft Graph 试图解决的问题之一。用于访问所有 Microsoft 数据的单个端点和令牌。
另一个解决方案是使用您收到的授权代码向两个不同的端点请求两个令牌。根据您使用的库以及您遵循的特定流程,这可能比不完成更难,但总的来说,authorization code grant flow is used to sign in a user. After the user is redirected to the Microsoft Login Page, and then successfully signs in, your service receives an authorization code, which it then exchanges for an access token using the Token Endpoint. This authorization code can be used to get an access token for any resource the client has been configured to call, so you can call the token endpoint twice, with two different resource
values, and get back two access tokens. I do this in one of my Python/Flask samples.
最后,假设您取回了特定资源的访问令牌和刷新令牌,然后您可以使用刷新令牌为应用已获得授权的其他资源获取令牌。
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 了解如何执行此操作。
我有点困惑如何获得适用于共享点网站以及图表的不记名令牌 api。
我们正在使用 MFA(多因素身份验证),因此当用户尝试登录时我们会收到一条短信。这一切都有效,我们得到了一个令牌,但我指向的资源是 https://srmukdev.sharepoint.com/, how can we use this token to access the https://graph.microsoft.com/ api。
目前它不起作用。我可以提出单独的登录请求,但我们不想这样做,因为它需要使用相同的令牌访问两个部分?有没有一种方法可以将一个标记转换为另一个标记?至少有用的东西?
可以看到当前不同的是ResourceUrl
我使用的分享点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 的令牌。令牌是针对特定受众创建的,作为 Web API 令牌验证的一部分,他们将检查令牌的受众是否与其唯一标识符匹配。
我认为一种可能的解决方案是认识到 Microsoft Graph 令牌已经允许您访问 SharePoint API。参见documentation here。您应该能够仅获取 Microsoft Graph 的令牌,然后使用 Microsoft Graph 特定端点从您的 SharePoint 获取数据。这是 Microsoft Graph 试图解决的问题之一。用于访问所有 Microsoft 数据的单个端点和令牌。
另一个解决方案是使用您收到的授权代码向两个不同的端点请求两个令牌。根据您使用的库以及您遵循的特定流程,这可能比不完成更难,但总的来说,authorization code grant flow is used to sign in a user. After the user is redirected to the Microsoft Login Page, and then successfully signs in, your service receives an authorization code, which it then exchanges for an access token using the Token Endpoint. This authorization code can be used to get an access token for any resource the client has been configured to call, so you can call the token endpoint twice, with two different resource
values, and get back two access tokens. I do this in one of my Python/Flask samples.
最后,假设您取回了特定资源的访问令牌和刷新令牌,然后您可以使用刷新令牌为应用已获得授权的其他资源获取令牌。
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 了解如何执行此操作。