如何排查 Azure Active Directory B2C 自定义属性中的验证错误

How to troubleshoot validation errors in Azure Active Directory B2C custom attributes

Azure AD B2C 自定义策略验证失败,并且没有提及导致验证错误的原因。

我已经为我的应用程序定义了自定义策略,在我向注册过程添加一个简单的 companyName 字符串之前一切正常。我按照 this guide 中详述的步骤添加了一个字段以在注册时收集。在成功上传 TrustFrameworkBase 策略后,我 运行 遇到了上传 singup_signing 自定义策略的问题。它告诉我

Validation failed: 1 validation error(s) found in policy "B2C_1A_SIGNUP_SIGNIN" of tenant "xxxxx".Output Claim 'companyName' is not supported in Azure Active Directory Provider technical profile 'AAD-UserReadUsingObjectId' of policy 'B2C_1A_signup_signin'. If it is a claim with default value, add AlwaysUseDefaultValue="true" to the output claim mapping.

所以我按照建议做了,并将 AlwaysUseDefaultValue="true" 和 DefaultValue="" 属性添加到 'AAD-UserReadUsingObjectId' 技术配置文件中的 OutputClaim。这使我能够成功上传策略文件。

但是,当我测试 signup_signin 策略时,我收到一条消息,指出

Unable to validate the information provided.

我也为此租户设置了 Application Insights,看到了同样模糊的错误消息

Error returned was 400/Request_BadRequest: One or more property values specified are invalid.

我将声明类型添加到 FrameworkBase 中的声明模式

<ClaimType Id="companyName">
  <DisplayName>Company</DisplayName>
  <DataType>string</DataType>
  <UserHelpText>Your company</UserHelpText>
  <UserInputType>TextBox</UserInputType>
</ClaimType>

我将 PersistedClaim 添加到 TechnicalProfile 'AAD-UserWriteUsingLogonEmail' <PersistedClaim ClaimTypeReferenceId="companyName" />

我将 OutputClaim 添加到 TechnicalProfiles 'AAD-UserReadUsingEmailAddress' <OutputClaim ClaimTypeReferenceId="companyName" /> 和 'AAD-UserReadUsingObjectId' <OutputClaim ClaimTypeReferenceId="companyName" AlwaysUseDefaultValue="true" DefaultValue="" />

我也将 OutputClaim 添加到 signup_signin.xml <OutputClaim ClaimTypeReferenceId="companyName" />

我希望用户已成功注册,但却收到上面的验证错误

该示例使用 "city"。

"Your Azure AD B2C directory comes with a built-in set of attributes. Examples are Given Name, Surname, City, Postal Code, and userPrincipalName."

所以 "city" 在架构中。

我从错误中假设 "companyName" 不是。

要添加,您使用 custom attribute

所以会是 "extension_companyName"。