azure - 微软图: Can I (re)use the user's Bearer Token forwarded by AAD in order to make "delegated" calls to the Graph API?

标签 azure sharepoint azure-active-directory azure-functions microsoft-graph-api

我开发了调用 Azure 函数的 SharePoint(在线)SPFx Webpart(使用 TypeScript/JavaScript)。在调用 Azure Function 时,AzureAD 会转发一些 header ,例如:

..
authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNRO.........",
..
..
x-ms-client-principal: "eyJhdXRoX3R5cCI6ImFhZCIsImNsYWltcyI6W3sidHlwIjoiYXVkI..........",
x-ms-client-principal-id: "588301bd-048a-XXXX-XXXX-XXXX-XXXX",
x-ms-client-principal-idp: "aad",
x-ms-client-principal-name: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="412c24012439202c312d246f222e2c" rel="noreferrer noopener nofollow">[email protected]</a>",
..

这样我就可以从 Azure Function App 访问这些 header (从角度来看)。

问题

  1. 上述授权(承载) token 到底有什么用?

  2. 上述授权(承载) token 是“委托(delegate) token ”吗?然后,它可以用作“登录用户”的有效 token ,以便我能够对 Microsoft Graph 进行“委托(delegate)”调用。比如调用https://graph.microsoft.com/v1.0/me

  3. 如果问题 2 的答案是否定的,那么上述哪些用户 token /原则(由 AAD 转发)可用于对 Microsoft Graph 进行“委托(delegate)”调用?

  4. 如果这些 AAD 转发的用户 token /原则都不能用于“委托(delegate)”调用,这是否意味着从 Azure 函数调用 Microsoft Graph API 的唯一方式是通过“应用程序权限” “方法?

感谢您对我的困惑的帮助。

最佳答案

Note that: The Bearer token can be used to call Microsoft Graph API if the token contains aud as Graph.

我同意juunas的观点,您传递的 token 是ID token ,不能用于调用API。

要调用 Microsoft Graph API,您需要检索生成的访问 token 并检查 audscp 值是否。

例如,我生成了访问 token ,解码后,audscp 值如下所示:

enter image description here

通过使用访问 token ,我能够成功获取登录用户的详细信息,如下所示:

https://graph.microsoft.com/v1.0/me

enter image description here

要对 Microsoft Graph API 进行委托(delegate)调用,请确保检索访问 token 并尝试。

引用文献:

SPFx: Calling Microsoft Graph API from an AAD secured Azure Function on behalf of a user by Vardhaman Deshpande

关于azure - 微软图: Can I (re)use the user's Bearer Token forwarded by AAD in order to make "delegated" calls to the Graph API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75083425/

相关文章:

azure - 地形 Azure : how to configure Type of Data Disks when VM is provisioned from a Custom Image

javascript - 使用 JavaScript 更改当前主机的链接

java - 来自 Java Web 应用程序的 SharePoint Web 服务使用 CXF 和 Kerberos/NTLM 身份验证

css - 在 Sharepoint 2010(非可视化)Web 部件中包含 CSS

azure - AADSTS90094 无法向应用程序发布者授予权限是 'Microsoft Accounts'

java - AADAuthenticationFilter 仅调用一次

azure - 如何触发/强制 Azure Batch 池自动缩放公式

azure - 仅为选定的 VM 启用 Azure 安全中心吗?

azure - 在浏览器中列出 Azure 存储 blob 内容

azure - 当主租户中的帐户被删除时, guest 租户中的 Azure AD guest 帐户会发生什么情况?