在ADB2C自定义策略中自定义注册页面

时间:2018-07-18 14:04:10

标签: azure-ad-b2c

我们正在使用自定义策略,并且已在注册页面中添加了一些字段。我们有一个DateTimeDropdown声明类型,允许用户选择出生日期。以下是声明的政策配置:

<ClaimType Id="birthDate">
  <DisplayName>Birth Date</DisplayName>
  <DataType>date</DataType>
  <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="birth_date" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="birth_date" />
      <Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/birthdate" />
  </DefaultPartnerClaimTypes>
  <UserInputType>DateTimeDropdown</UserInputType>
</ClaimType>

This is how it renders on the page.

“年份”选择的范围是从1900开始到2050。是否有任何方法可以配置来更改或限制此下拉列表中的值?

1 个答案:

答案 0 :(得分:0)

这可以使用Predicates和PredicateValidations完成。 更新您的ClaimType以包含PredicateValidation;

<ClaimType Id="birthDate">
  <DisplayName>Birth Date</DisplayName>
  <DataType>date</DataType>
  <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="birth_date" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="birth_date" />
      <Protocol Name="SAML2"     PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/birthdate" />
  </DefaultPartnerClaimTypes>
  <UserInputType>DateTimeDropdown</UserInputType>
  <PredicateValidationReference Id="CustomDateRange" />
</ClaimType>

然后在</ClaimsSchema><ClaimsTransformation>之间添加以下内容;

 <Predicates>
  <Predicate Id="DateRange" Method="IsDateRange" HelpText="The date must be between 1920-01-01 and today.">
    <Parameters>
      <Parameter Id="Minimum">1920-01-01</Parameter>
      <Parameter Id="Maximum">Today</Parameter>
    </Parameters>
  </Predicate>
</Predicates>
<PredicateValidations>
  <PredicateValidation Id="CustomDateRange">
    <PredicateGroups>
      <PredicateGroup Id="DateRangeGroup">
        <PredicateReferences>
          <PredicateReference Id="DateRange" />
        </PredicateReferences>
      </PredicateGroup>
    </PredicateGroups>
  </PredicateValidation>
</PredicateValidations>
相关问题