你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure Active Directory B2C 自定义策略中定义Microsoft Entra 技术配置文件

重要

自 2025 年 5 月 1 日起,Azure AD B2C 将不再可供新客户购买。 在我们的常见问题解答中了解详细信息

注释

在 Azure Active Directory B2C 中,自定义策略 主要用于解决复杂场景。 对于大多数场景,我们建议您使用内置的用户流。 如果未这样做,请通过 Active Directory B2C 中的自定义策略入门来了解自定义策略初学者包。

Azure Active Directory B2C (Azure AD B2C) 为 Microsoft Entra 用户管理提供支持。 本文介绍用于与支持此标准化协议的声明提供程序交互的技术配置文件的具体信息。

协议

“Protocol”元素的“Name”属性必须设置为 处理程序属性必须包含协议处理程序程序集Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null的完全限定名称。

遵循 自定义策略初学者包 Microsoft Entra 技术配置文件包括 AAD-Common 技术配置文件。 Microsoft Entra 技术配置文件未指定协议,因为协议是在 AAD-Common 技术配置文件中配置的:

  • AAD-UserReadUsingAlternativeSecurityIdAAD-UserReadUsingAlternativeSecurityId-NoError - 在目录中查找社交帐户。
  • AAD-UserWriteUsingAlternativeSecurityId - 创建新的社交帐户。
  • AAD-UserReadUsingEmailAddress - 在目录中查找本地帐户。
  • AAD-UserWriteUsingLogonEmail - 创建新的本地帐户。
  • AAD-UserWritePasswordUsingObjectId - 更新本地帐户的密码。
  • AAD-UserWriteProfileUsingObjectId - 更新本地或社交帐户的用户配置文件。
  • AAD-UserReadUsingObjectId - 读取本地或社交帐户的用户配置文件。
  • AAD-UserWritePhoneNumberUsingObjectId - 编写本地或社交帐户的 MFA 电话号码

以下示例显示了 AAD-Common 技术配置文件:

<TechnicalProfile Id="AAD-Common">
  <DisplayName>Azure Active Directory</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

  <CryptographicKeys>
    <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
  </CryptographicKeys>

  <!-- We need this here to suppress the SelfAsserted provider from invoking SSO on validation profiles. -->
  <IncludeInSso>false</IncludeInSso>
  <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>

InputClaims

InputClaims 元素包含一个声明,该声明用于在目录中查找帐户,或创建新的帐户。 所有Microsoft Entra 技术配置文件的输入声明集合中必须只有一个 InputClaim 元素。 可能需要将策略中定义的声明的名称映射到Microsoft Entra ID 中定义的名称。

若要读取、更新或删除现有用户帐户,输入声明是一个密钥,用于唯一标识 Microsoft Entra 目录中的帐户。 例如 ,objectIduserPrincipalNamesignInNames.emailAddresssignInNames.userNamealternativeSecurityId

若要创建新的用户帐户,输入声明是唯一标识本地或联合帐户的密钥。 例如,本地帐户: signInNames.emailAddresssignInNames.userName。 对于联合帐户: alternativeSecurityId

InputClaimsTransformations 元素可能包含用于修改输入声明或生成新声明的输入声明转换元素的集合。

OutputClaims

OutputClaims 元素包含由 Microsoft Entra 技术配置文件返回的声明列表。 可能需要将策略中定义的声明的名称映射到Microsoft Entra ID 中定义的名称。 还可以包含Microsoft Entra ID 未返回的声明,前提是设置了 DefaultValue 属性。

OutputClaimsTransformations 元素可能包含用于修改输出声明或生成新声明的 OutputClaimsTransformation 元素的集合。

例如, AAD-UserWriteUsingLogonEmail 技术配置文件创建本地帐户并返回以下声明:

  • objectId,它是新帐户的标识符
  • newUser,指示用户是否为新用户
  • authenticationSource,用于将身份验证设置为 localAccountAuthentication
  • userPrincipalName,它是新帐户的用户主体名称
  • signInNames.emailAddress,这是帐户登录名称,类似于 电子邮件 输入声明
<OutputClaims>
  <OutputClaim ClaimTypeReferenceId="objectId" />
  <OutputClaim ClaimTypeReferenceId="newUser" PartnerClaimType="newClaimsPrincipalCreated" />
  <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="localAccountAuthentication" />
  <OutputClaim ClaimTypeReferenceId="userPrincipalName" />
  <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
</OutputClaims>

PersistedClaims

PersistedClaims 元素包含所有应由 Microsoft Entra ID 保留的所有值,这些值在策略的 ClaimsSchema 节中定义的声明类型与 Microsoft Entra 属性名称中已定义的声明类型之间可能映射信息。

AAD-UserWriteUsingLogonEmail 技术配置文件(用于创建新的本地帐户)保留以下声明:

  <PersistedClaims>
    <!-- Required claims -->
    <PersistedClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" />
    <PersistedClaim ClaimTypeReferenceId="newPassword" PartnerClaimType="password"/>
    <PersistedClaim ClaimTypeReferenceId="displayName" DefaultValue="unknown" />
    <PersistedClaim ClaimTypeReferenceId="passwordPolicies" DefaultValue="DisablePasswordExpiration" />

    <!-- Optional claims. -->
    <PersistedClaim ClaimTypeReferenceId="givenName" />
    <PersistedClaim ClaimTypeReferenceId="surname" />
  </PersistedClaims>

声明的名称是Microsoft Entra 属性的名称,除非指定 PartnerClaimType 属性,其中包含Microsoft Entra 属性名称。

作的要求

  • 所有Microsoft Entra 技术配置文件的声明包中必须只有一个 InputClaim 元素。
  • 用户配置文件属性文章介绍了可在输入声明、输出声明和持久化声明中使用的受支持的 Azure AD B2C 用户配置文件属性。
  • 如果作为 WriteDeleteClaims,则它还必须出现在 PersistedClaims 元素中。
  • userPrincipalName 声明的值必须采用 user@tenant.onmicrosoft.com.
  • displayName 声明是必需的,不能为空字符串。

Microsoft Entra 技术配置文件作

读取

读取作读取有关单个用户帐户的数据。 以下技术配置文件使用用户的 objectId 读取有关用户帐户的数据:

<TechnicalProfile Id="AAD-UserReadUsingObjectId">
  <Metadata>
    <Item Key="Operation">Read</Item>
    <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
  </Metadata>
  <IncludeInSso>false</IncludeInSso>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
  </InputClaims>
  <OutputClaims>

    <!-- Required claims -->
    <OutputClaim ClaimTypeReferenceId="strongAuthenticationPhoneNumber" />

    <!-- Optional claims -->
    <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
    <OutputClaim ClaimTypeReferenceId="displayName" />
    <OutputClaim ClaimTypeReferenceId="otherMails" />
    <OutputClaim ClaimTypeReferenceId="givenName" />
    <OutputClaim ClaimTypeReferenceId="surname" />
  </OutputClaims>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>

写入

写入作创建或更新单个用户帐户。 以下技术配置文件创建新的社交帐户:

<TechnicalProfile Id="AAD-UserWriteUsingAlternativeSecurityId">
  <Metadata>
    <Item Key="Operation">Write</Item>
    <Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">true</Item>
    <Item Key="UserMessageIfClaimsPrincipalAlreadyExists">You are already registered, please press the back button and sign in instead.</Item>
  </Metadata>
  <IncludeInSso>false</IncludeInSso>
  <InputClaimsTransformations>
    <InputClaimsTransformation ReferenceId="CreateOtherMailsFromEmail" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="AlternativeSecurityId" PartnerClaimType="alternativeSecurityId" Required="true" />
  </InputClaims>
  <PersistedClaims>
    <!-- Required claims -->
    <PersistedClaim ClaimTypeReferenceId="alternativeSecurityId" />
    <PersistedClaim ClaimTypeReferenceId="userPrincipalName" />
    <PersistedClaim ClaimTypeReferenceId="mailNickName" DefaultValue="unknown" />
    <PersistedClaim ClaimTypeReferenceId="displayName" DefaultValue="unknown" />

    <!-- Optional claims -->
    <PersistedClaim ClaimTypeReferenceId="otherMails" />
    <PersistedClaim ClaimTypeReferenceId="givenName" />
    <PersistedClaim ClaimTypeReferenceId="surname" />
  </PersistedClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="objectId" />
    <OutputClaim ClaimTypeReferenceId="newUser" PartnerClaimType="newClaimsPrincipalCreated" />
    <OutputClaim ClaimTypeReferenceId="otherMails" />
  </OutputClaims>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
  <UseTechnicalProfileForSessionManagement ReferenceId="SM-AAD" />
</TechnicalProfile>

DeleteClaims

DeleteClaims作从提供的声明列表中清除信息。 以下技术配置文件删除声明:

<TechnicalProfile Id="AAD-DeleteClaimsUsingObjectId">
  <Metadata>
    <Item Key="Operation">DeleteClaims</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
  </InputClaims>
  <PersistedClaims>
    <PersistedClaim ClaimTypeReferenceId="objectId" />
    <PersistedClaim ClaimTypeReferenceId="Verified.strongAuthenticationPhoneNumber" PartnerClaimType="strongAuthenticationPhoneNumber" />
  </PersistedClaims>
  <OutputClaims />
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>

DeleteClaimsPrincipal

DeleteClaimsPrincipal作从目录中删除单个用户帐户。 以下技术配置文件使用用户主体名称从目录中删除用户帐户:

<TechnicalProfile Id="AAD-DeleteUserUsingObjectId">
  <Metadata>
    <Item Key="Operation">DeleteClaimsPrincipal</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
  </InputClaims>
  <OutputClaims/>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>

以下技术配置文件使用 alternativeSecurityId 删除社交用户帐户:

<TechnicalProfile Id="AAD-DeleteUserUsingAlternativeSecurityId">
  <Metadata>
    <Item Key="Operation">DeleteClaimsPrincipal</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="alternativeSecurityId" Required="true" />
  </InputClaims>
  <OutputClaims/>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>

元数据

特征 必选 DESCRIPTION
操作 是的 要执行的作。 可能的值:ReadWriteDeleteClaimsDeleteClaimsPrincipal
RaiseErrorIfClaimsPrincipalDoesNotExist 如果目录中不存在用户对象,则引发错误。 可能的值:truefalse
RaiseErrorIfClaimsPrincipalAlreadyExists 如果用户对象已存在,则引发错误。 可能的值:truefalse。 此元数据仅适用于写入作。
ApplicationObjectId 扩展属性的应用程序对象标识符。 值:应用程序的 ObjectId。 有关详细信息,请参阅 “使用自定义属性”。
ClientId 作为第三方访问租户的客户端标识符。 有关详细信息,请参阅 在自定义配置文件编辑策略中使用自定义属性
IncludeClaimResolvingInClaimsHandling 对于输入和输出声明,指定声明 解析 是否包含在技术配置文件中。 可能的值:truefalse(默认值)。 如果要在技术配置文件中使用声明解析程序,请将此设置为 true

UI 元素

以下设置可用于配置失败时显示的错误消息。 应在 自断言 技术配置文件中配置元数据。 可以将错误消息本地化

特征 必选 DESCRIPTION
UserMessageIfClaimsPrincipalAlreadyExists 如果要引发错误(请参阅 RaiseErrorIfClaimsPrincipalAlreadyExists 属性说明),请指定要向用户显示的消息(如果用户对象已存在)。
UserMessageIfClaimsPrincipalDoesNotExist 如果要引发错误(请参阅 RaiseErrorIfClaimsPrincipalDoesNotExist 属性说明),请指定在用户对象不存在时向用户显示的消息。

后续步骤

请参阅以下文章,了解如何使用 Microsoft Entra 技术配置文件: