gpt4 book ai didi

使用 Azure Active Directory v1 连接登录后,Azure 使用详细信息 API 显示 "Authentication failed"

转载 作者:行者123 更新时间:2023-12-03 02:49:44 25 4
gpt4 key购买 nike

我完全按照这个链接https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-authentication?view=azure-bot-service-4.0&tabs=aadv1%2Ccsharp%2Cbot-oauth并创建了 Azure AD 应用程序注册,并为我的 Web 应用程序机器人使用了 Azure Active Directory v1。

登录后,我查看了 token ,但使用该 token 我无法访问 Azure API,如 Postman 中的以下响应所示:

{
"error": {
"code": "AuthenticationFailed",
"message": "Authentication failed."
}

我在下面调用了 Azure API:

https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.Consumption/usageDetailsapi-version=2018-10-01

在 Azure AD 中的应用注册中,我已授予访问 Azure API 的权限:

enter image description here

enter image description here

在我的 Web 应用程序机器人 -> 设置 -> OAuth 连接设置中,我选择:

ClientId -> My application client id
ClinetSecret -> My application client secret
GrantType -> I does not know what to give so I just typed "authorization_code" (If this wrong then Where I need to find my grantType)
LoginURL -> https://login.microsoftonline.com
TenantId -> common (To allow any user)
ResourceURL -> https://graph.microsoft.com/
Scopes -> I just left blank

为什么我无法使用该 token 访问 Azure API?

任何帮助。谢谢

最佳答案

Azure AD 颁发的访问 token 始终用于特定资源。 token 用于哪种服务由 token 的“受众”(在 aud 声明中)标识。使用 v1 端点时,应用请求访问 token 的资源在授权请求的 resource 参数中标识。在 v2 端点中,资源被标识为 scope 参数的一部分。

就您而言,您配置机器人获取 token 的资源是 Microsoft Graph (https://graph.microsoft.com),但您随后尝试使用用于调用 Azure 管理 API 的生成 token 。 Azure 管理 API 所做的第一件事是检查它收到的访问 token 是否确实是供其使用的。如果受众不匹配,它将立即响应错误。

您需要配置机器人以获取 Azure 管理 API 的 token ,而不是尝试获取 Microsoft Graph 的 token 。您应该使用 https://management.azure.com(Azure 管理 API 的资源 URI),而不是 https://graph.microsoft.com(是 Microsoft Graph 的资源 URI。

关于使用 Azure Active Directory v1 连接登录后,Azure 使用详细信息 API 显示 "Authentication failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56770167/

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