我开发了调用 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 (从角度来看)。
问题
上述
授权(承载)
token 到底有什么用?上述
授权(承载)
token 是“委托(delegate) token ”吗?然后,它可以用作“登录用户”的有效 token ,以便我能够对 Microsoft Graph 进行“委托(delegate)”调用。比如调用https://graph.microsoft.com/v1.0/me
如果问题 2 的答案是否定的,那么上述哪些用户 token /原则(由 AAD 转发)可用于对 Microsoft Graph 进行“委托(delegate)”调用?
如果这些 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 并检查 aud
和 scp
值是否。
例如,我生成了访问 token ,解码后,aud
和 scp
值如下所示:
通过使用访问 token ,我能够成功获取登录用户的详细信息,如下所示:
https://graph.microsoft.com/v1.0/me
要对 Microsoft Graph API 进行委托(delegate)调用,请确保检索访问 token 并尝试。
引用文献:
关于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/