向自定义策略添加限制并使声明成为可选的 Azure B2C
Add restrictions to custom policy and make claim optional Azure B2C
我正在尝试使用 LocalAccountSignUpWithLogonName 自定义收集用户详细信息 policy.I 已添加 <OutputClaim ClaimTypeReferenceId="email" />
以 LocalAccountSignUpWithLogonName 作为输出声明。我想将电子邮件字段设为可选,但如果用户输入我要启用的电子邮件,restrictions.Below 是我的电子邮件声明
<ClaimType Id="email">
<DisplayName>Your Email Address</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OpenIdConnect" PartnerClaimType="email" />
</DefaultPartnerClaimTypes>
<UserHelpText>Email address that can be used to contact you.</UserHelpText>
<UserInputType>TextBox</UserInputType>
<Restriction>
<Pattern RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" HelpText="Please enter a valid email address." />
</Restriction>
但是当我将模式限制添加到 claim 时,它使该字段成为必填项。
我通过将正则表达式从 RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"
更改为 RegularExpression="^$|^[a-zA-Z0-9.+!#$%&'^_
{}~-]+@[a-zA-Z0-9-]+(?:.[a- zA-Z0-9-]+)*$" `.
我不得不在表达式前加上 ^$|
前缀,它接受 blank/empty 或实际的电子邮件。
我正在尝试使用 LocalAccountSignUpWithLogonName 自定义收集用户详细信息 policy.I 已添加 <OutputClaim ClaimTypeReferenceId="email" />
以 LocalAccountSignUpWithLogonName 作为输出声明。我想将电子邮件字段设为可选,但如果用户输入我要启用的电子邮件,restrictions.Below 是我的电子邮件声明
<ClaimType Id="email">
<DisplayName>Your Email Address</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OpenIdConnect" PartnerClaimType="email" />
</DefaultPartnerClaimTypes>
<UserHelpText>Email address that can be used to contact you.</UserHelpText>
<UserInputType>TextBox</UserInputType>
<Restriction>
<Pattern RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" HelpText="Please enter a valid email address." />
</Restriction>
但是当我将模式限制添加到 claim 时,它使该字段成为必填项。
我通过将正则表达式从 RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"
更改为 RegularExpression="^$|^[a-zA-Z0-9.+!#$%&'^_
{}~-]+@[a-zA-Z0-9-]+(?:.[a- zA-Z0-9-]+)*$" `.
我不得不在表达式前加上 ^$|
前缀,它接受 blank/empty 或实际的电子邮件。