首页 > 解决方案 > 使用 Azure Active Directory 和 Azure Active Directory B2C 时,如何获得标准 OpenID 连接声明?

问题描述

We are developing an ASP.NET core 2.2 web application by using IdentityServer 4 as a gateway to other identity providers following the federation gateway architecture.

The application we are developing is the actual identity provider web application which is, as explained above, just a gateway to some configured upstream identity providers.

The user basically configures his preferred upstream identity providers and our application takes care of configuring IdentityServer4 so that the configured providers are used as external identity providers for identity server itself.

The requirement for the application user is that each configured provider must be compliant with the OpenID connect protocol. Each upstream provider is in fact registered with identity server 4 by using the ASP.NET core authentication handler for OpenID connect.

During the development phase we are testing the application by using Azure active directory B2C and our company's instance of Azure Active Directory as test upstream identity providers.

We ask for 3 different scopes during the authentication: openid, profile and email.

We do so because the only user claims that we need from the external provider are sub (provided by the openid scope), given_name and family_name (provided by the profile scope) and email (provided by the email scope). Notice that the email claim is really important for us, because we want to use it as the primary key by which identifying the system users (this is relevant for the Azure Active Directory B2C issue explained below).

These are standard open id connect scopes and claims so we expected to find them easily in our test providers. Unfortunately the reality is different and neither Azure Active Directory nor Azure Active Directory B2C send all of these claims.

What we actually get are the following claims:

我的问题基本上如下:

感谢您的帮助!

标签: azureasp.net-coreazure-active-directoryidentityserver4openid-connect

解决方案


您指的是OPTIONAL由 OpenID Connect 标准标记的声明。

就 Azure AD(不是 B2C)而言,这里是文档:

对于 B2C,嗯,确实没有关于此的文档,或者我在查找它时遇到问题。这是一个通用的 B2C 代币参考文档。但只需转到您的user_flow并为应用程序(依赖方)定义请求的声明:

在此处输入图像描述

如何在 B2C 环境中发出电子邮件声明存在一个普遍的挑战。因为您可能有一个本地用户,或者一个社交用户(包括在您的情况下通过 B2C 联合的 Azure AD 用户),甚至是一个远程用户(具有自定义流的更复杂的场景)。所以你并没有真正拥有电子邮件的真实来源。

所谓self asserted的名字和姓氏 - 最终用户提供信息,您(B2C)只需将其保存到配置文件中。因此,您的应用程序正在获取用户提供的信息。它可能是任何东西。

您当然可以创建自定义声明并为其命名,email而不是emails在 B2C 中。但是您必须最终决定哪个是此声明的来源。您可以使用自定义流程来实现该目标。

我通常也会反对电子邮件是主键,甚至是某些东西的匹配项。有足够的情况,尤其是在公司内部,员工的电子邮件可能会发生变化。并且您的应用程序不应依赖于电子邮件是用户配置文件的不可变属性这一事实。

有了这个,我相信我只回答了第一个问题。

至于后者:

是否可以假设任何声明符合 OpenID connect 的身份提供者都能够向我们提供这四个声明?

不要忘记您所引用的声明OPTIONALOpenID Connect 规范中进行了标记。这意味着身份提供者不必为了兼容 OpenID Connect 而实现这些。更具体地说,文档指出:

授权服务器将以下范围请求的声明视为自愿声明。

但是是的 - Azure Active Directory 提供了所有这些 - 带有可选声明的配置。B2C 还为他们提供了更复杂的email索赔解决方法。


推荐阅读