gpt4 book ai didi

azure - 在哪里可以找到 Microsoft 应用程序的应用程序 ID URI?

转载 作者:行者123 更新时间:2023-12-03 17:14:06 25 4
gpt4 key购买 nike

我正在尝试以我注册的应用程序身份登录,并授予以下权限:Azure 门户 > 应用程序注册 > 应用程序注册(预览) > 我的应用程序名称 - API 权限

根据this documentation ,当请求 token 时,我必须在范围参数中传递我的资源标识符(APP ID URI)。我确信这个作用域参数是导致我出现问题的原因。

我尝试了范围的不同参数。

  1. https://graph.microsoft.com/.default:这适用于基本功能,例如阅读日历,但我相信默认权限很少能满足我的需求。既然这个有效,我相信我的其他参数是正确的,范围就是问题。

  2. [APP-ID]/.default:这给了我一个成功的响应,但是,每当我尝试发出任何请求(包括基本的读取日历请求)时,我都会收到无效的身份验证 token 。我可以向您保证,我正在传递从 token 请求中检索到的正确 token 。

  3. 基于在线建议的多个不同的 URL 组合。全部返回

    "The resource principal {resource-url} was not found in tenant {id}.

我坚信问题在于我没有为我的应用程序传递正确的APP ID URI。谁能告诉我在哪里可以找到这个资源?我在网上搜索到的所有内容都是 2 年多前的,对于新的 Azure 门户似乎并不相同。

最佳答案

对于客户端凭据(即在没有用户的情况下获取 token ),您需要传递 https://graph.microsoft.com/.default 作为您的范围

https://graph.microsoft.com/.default 提供的权限是您在门户中注册应用程序时指定的“应用程序权限”:

enter image description here

添加应用程序所需的所有“应用程序权限”后,您需要为租户中的这些范围“授予同意”(这是 API 权限选项卡底部的按钮。

完成这些后,您需要向 /token 端点发出 POST (换行符只是为了便于阅读,这应该是单个字符串) :

POST https://login.microsoftonline.com/{{tenantDomain}}/oauth2/token
Content-Type: application/x-www-form-urlencoded

client_id={your-app-id}
&scope=https://graph.microsoft.com/.default
&client_secret={your-client-secret}
&grant_type=client_credentials

这将返回如下内容:

{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1554431330",
"not_before": "1554427430",
"resource": "00000003-0000-0000-c000-000000000000",
"access_token": "eyJ0eXAiOiJKV1QiLCJub25jZS..."
}

当您调用 Graph 时,您需要将 Authorization header 设置为 token_type access_token。因此调用 /users 看起来像这样:

GET https://graph.microsoft.com/v1.0/users
Authorization:"Bearer eyJ0eXAiOiJKV1QiLCJub25jZS..."
Host:"graph.microsoft.com"
Accept:"application/json"

关于azure - 在哪里可以找到 Microsoft 应用程序的应用程序 ID URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55522168/

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