使用Azure AD通过OAuth2对Azure API管理进行身份验证

beewest

我正在通过阅读文章尝试通过OAuth2使用OAuth2保护APIM API:通过对Azure AD使用OAuth 2.0授权来保护Azure API管理中的Web API后端

AzureAPIM-OAuth2

AzureAD-后端应用程序:

  • 范围:Files.All

AzureAD-客户端应用程序:

对于Demo Conference API,将“验证JWT”策略添加到入站处理中,其中入站3a0cf09b-IDb7c31179-为后端应用程序应用ID:在此处输入图片说明

在开发人员门户中,使用返回令牌对AzureAD进行身份验证成功: 在此处输入图片说明

但是,调用API会导致授权失败: 在此处输入图片说明

检查jwt.io中收到的令牌,我发现"aud": "00000003-0000-0000-c000-000000000000"不是后端应用程序应用程序ID:

{
  "aud": "00000003-0000-0000-c000-000000000000",
  "iss": "https://sts.windows.net/3a0cf09b-xxx/",
  "app_displayname": "client-app",
  "appid": "05a245fb-xxx",
  "scp": "Files.Read User.Read profile openid email",
  "tenant_region_scope": "OC",
  "tid": "3a0cf09b-2952-4673-9ace-0e1bf69ee23a",
  "unique_name": "[email protected]",
}

API测试HTTP响应跟踪显示validate-jwt上的错误:

validate-jwt (-0.138 ms)
{
    "message": "JWT Validation Failed: Claim value mismatch: aud=b7c31179-xxx.."
}

更换aud由值令牌00000003-0000-0000-c000-000000000000或取出required-claims的在validate-jwt政策得到它的工作。

Any idea please?

Hury Shen

It seems you choose v1 endpoint of OAuth2 authorization but not v2 endpoint, so the value of aud in access token should be like b7c31179-xxxx.... but not api://b7c31179-xxxx..... So there are no mistakes in your steps of get access token.

According to some test in my side, the cause of this problem is you did not specify a parameter resource with the value of the backend-app application id when you configure OAuth2.0 in your APIM. The document you refer to also mentions this (I test with not specify this parameter, it shows same problem with yours) 在此处输入图片说明

So to solve this problem, please go to your APIM and click "OAuth 2.0" tab, edit the item you created. Add a parameter resource with value of the backend-app application id. 在此处输入图片说明

注意:添加参数resource并单击“保存”按钮时,请再次打开该项目,并检查“客户端密码”框是否为空。当我在一边测试时,“添加参数”框后的“客户端密码”框显示为空resource,这可能是该页面上的错误。如果“客户密码”为空,则可能会显示错误消息,例如The request body must contain the following parameter: 'client_assertion' or 'client_secret'在开发人员门户中获取访问令牌时。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Azure API管理-身份验证:OAuth2与证书

使用Azure管理API进行身份验证

无法对Azure上的API管理进行资源所有者密码OAuth2身份验证

Azure API管理和身份验证

使用IdentityServer和Azure API管理进行用户身份验证

如何使用 AZURE AD 为 Apache Kafka 集群配置 OAuth2 身份验证

如何使用 Azure Management Fluent API 进行身份验证

使用 REST API 在 Go 中对 Azure 进行身份验证

通过API的Azure CDN管理(身份验证问题)

使用Azure B2C对用户进行身份验证以访问API管理背后的微服务

Azure AD - Oauth2 返回无效的身份验证令牌

使用 Graph API 对 Azure AD B2C 上的用户进行身份验证

使用 azure AD B2C 进行 blazor web api 身份验证

使用 Azure 进行 HMAC 身份验证

如何使用函数身份验证或Azure AD服务主体对Azure函数进行身份验证

使用Azure AD,ReactJS和NodeJS对用户进行身份验证并使用Graph API

从 AWS Lambda 通过 Azure AD 对用户进行身份验证

如何使用REST API使用OAuth2和React Native进行身份验证?

在.NET Core API上使用Azure AD对用户进行身份验证?

使用带有节点的Azure AD进行身份验证

如何使用Azure AD对VueJS应用进行身份验证?

使用Jmeter进行Azure AD身份验证

使用Azure AD对Samba进行身份验证

在iOS中使用NSURLSessions对服务器API进行oAuth2身份验证

如何在 Google Analytics Reporting API 中使用 OAuth2 进行身份验证?

在iOS上使用OAuth2进行身份验证

使用OAuth2进行Geoserver身份验证

使用托管身份对Azure Service Bus进行身份验证的REST API调用

如何使用Azure广告帐户通过nodejs api对react.js应用进行身份验证?