我完全按照此链接https://docs.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。
登录后,我查看了令牌,但是使用该令牌,我无法访问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的权限:
在我的Web App Bot->设置-> 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
为什么我不能使用该令牌访问Azure API?
任何帮助。谢谢
由Azure AD发出的访问令牌将始终用于特定资源。令牌的“受众”(在aud
权利要求中)标识了令牌打算用于哪种服务。使用v1端点时,resource
在授权请求的参数中标识了应用程序为其请求访问令牌的资源。在v2端点中,资源被标识为scope
参数的一部分。
在您的情况下,您已配置机器人以获取令牌的资源是Microsoft Graph(https://graph.microsoft.com
),但随后您尝试使用生成的令牌来调用Azure管理API。Azure管理API要做的第一件事是检查它接收到的访问令牌是否实际上是针对它的。如果观众不匹配,它将立即以错误响应。
无需尝试获取Microsoft Graph的令牌,而是需要配置机器人以获取Azure Management API的令牌。您应该使用https://management.azure.com
,这是Azure管理APIhttps://graph.microsoft.com
的资源URI ,而不是Microsoft Graph的资源URI。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句