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

Authorisation with Azure API Management and oAuth2

我有一个 WebAPI (A) 托管在 Azure 上,受 Azure B2C (B) 保护,移动应用程序正在调用 (C) - 这一切都正常工作。

我现在想允许第三方通过同一平台上的 API 管理访问我的 API,但我对身份验证和 "audiences" 感到非常困惑。

已根据 Azure 文档配置了 API 管理开发人员门户,以便当开发人员在门户上进行测试调用时,它会提示使用 B2C 域 (B) 进行身份验证。为此,它使用针对 B2C 域注册的应用程序。

然而,当我想从第三方系统实施 API 时 (D) 我需要允许系统在调用我的 API 时模拟用户 (A) 以便进行操作在域 (B) 上经过身份验证的用户的上下文中。

我知道 B2C 尚不支持 "On Behalf Of" 作为有效流程,因此我使用 hellojs 在客户端上获取访问令牌,然后通过自定义头传递给第三方系统 API然后它作为授权 header 附加到它对 API.

的调用

API 管理产品需要 "subscription key" 来标识第三方实施可以使用的产品。

  1. 关于身份验证部分,这是否意味着使用我的 API 的每个第三方系统都将使用相同的 oAuth "audience" ID,因此使用相同的 Active Directory 应用程序?

  2. 我觉得每个第三方实现在 Azure Ad 上都有不同的应用程序,但这意味着我的 Web API 需要识别大量的受众 ID并重定向 uris?

最后,我如何 "hide" 来自 public 的 Web API 端点使用 - 使用受众 ID 肯定会让人们绕过 API 管理产品?

抱歉,如果我混淆了任何术语。

1) Does this mean with regards to the authentication part that every third party system using my API would use the same oAuth "audience" id and therefore the same Active Directory app?

他们将使用相同的 resource/scope ID(即观众),例如https://yourwebapiAppIDURI/Read 但他们都有自己的应用程序 ID。

2) It makes more sense to me that each third party implementation would have a different app on Azure Ad but that would mean my Web API would need to recognise a huge number of audience ids and redirect uris?

是的,他们应该将他们的应用程序注册为您的 B2C 身份验证服务器的客户端。 应在 AAD 门户中设置第 3 方应用程序以委派访问您的 Web API (. "Access yourwebAPIname")。如果您的网站 API 公开了任何范围,那么也可以委托对这些范围的访问。

现在,当他们通过将用户重定向到您的 Auth Server 来启动令牌请求时,他们应该提供他们的客户端 ID 和您网站的 resource/scope 值 APIs App ID URL 例如https://yourwebapiAppIDURI/Read

这应该会产生一个令牌:

audhttps://yourwebapiAppIDURI/

关联的应用程序 ID 的值

scp Read

的值

好的,所以 B2C 不使用同意:

Azure AD B2C does not ask your client application users for their consent. Instead, all consent is provided by the admin, based on the permissions configured between the applications described above. If a permission grant for an application is revoked, all users who were previously able to acquire that permission will no longer be able to do so.