我有一个自定义属性,我想在身份验证时使用它。例如,我有另一个状态扩展属性,该属性可以具有可能的值,例如expired / blocked / inactive / active。在创建用户时,我将确保为此填充一个值。
在登录时,我还要考虑该扩展属性。用户可能输入的密码是正确的,但是仅仅因为他的扩展名属性状态的值已过期/已阻止/无效,所以我想拒绝登录并提供自定义的本地化错误消息。
注意:我正在使用自定义策略。
答案 0 :(得分:2)
您可以构建声明转换以确定用户帐户是否已激活,如果未激活,则显示错误消息。
首先,您必须声明一个声明类型,该声明类型表示用户帐户是否已激活:
<ClaimType Id="accountActivated">
<DisplayName>Account Activated</DisplayName>
<DataType>boolean</DataType>
</ClaimType>
接下来,您必须声明a CompareClaimToValue claims transformation以确定自定义属性是否设置为“活动”:
<ClaimsTransformation Id="CheckAccountActivated" TransformationMethod="CompareClaimToValue">
<InputClaims>
<InputClaim ClaimTypeReferenceId="extension_AccountStatus" TransformationClaimType="inputClaim1" />
</InputClaims>
<InputParameters>
<InputParameter Id="compareTo" DataType="string" Value="Active" />
<InputParameter Id="operator" DataType="string" Value="equal" />
<InputParameter Id="ignoreCase" DataType="string" Value="true" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="accountActivated" TransformationClaimType="outputClaim" />
</OutputClaims>
</ClaimsTransformation>
接下来,您必须声明an AssertBooleanClaimIsEqualToValue claims transformation以确保激活了用户帐户:
<ClaimsTransformation Id="EnsureAccountActivated" TransformationMethod="AssertBooleanClaimIsEqualToValue">
<InputClaims>
<InputClaim ClaimTypeReferenceId="accountActivated" TransformationClaimType="inputClaim" />
</InputClaims>
<InputParameters>
<InputParameter Id="valueToCompareTo" DataType="boolean" Value="true" />
</InputParameters>
</ClaimsTransformation>
接下来,您必须从 AAD-UserReadUsingObjectId 技术资料测试用户帐户已激活的副本中调用 EnsureAccountActivated 声明转换:
<TechnicalProfile Id="AAD-UserReadUsingObjectId-EnsureAccountActivated">
<OutputClaimsTransformations>
<OutputClaimsTransformation ReferenceId="CheckAccountActivated" />
<OutputClaimsTransformation ReferenceId="EnsureAccountActivated" />
</OutputClaimsTransformations>
<IncludeTechnicalProfile ReferenceId="AAD-UserReadUsingObjectId" />
</TechnicalProfile>
最后,您必须从 SelfAsserted-LocalAccountSignin-Email 技术配置文件的副本中调用 AAD-UserReadUsingObjectId-EnsureAccountActivated 技术配置文件以显示错误消息:>
<TechnicalProfile Id="SelfAsserted-LocalAccountSignin-Email-EnsureAccountActivated">
...
<Metadata>
...
<Item Key="UserMessageIfClaimsTransformationBooleanValueIsNotEqual">Whoops, your e-mail address hasn't been verified, contact Support.</Item>
</Metadata>
<ValidationTechnicalProfiles>
<ValidationTechnicalProfile ReferenceId="login-NonInteractive" />
<ValidationTechnicalProfile ReferenceId="AAD-UserReadUsingObjectId-EnsureAccountActivated" />
</ValidationTechnicalProfiles>
...
</TechnicalProfile>
更新:2019年4月3日
这绝对好用,但是在本地化自定义错误消息方面需要一些帮助。
您可以使用localization自定义错误消息。
第一步是enable localization,以支持英语和其他任何语言:
<BuildingBlocks>
...
<ContentDefinitions />
<Localization>
<SupportedLanguages DefaultLanguage="en">
<SupportedLanguage>en</SupportedLanguage>
<SupportedLanguage>es</SupportedLanguage>
</SupportedLanguages>
</Localization>
</BuildingBlocks>
第二步是为与 SelfAsserted-LocalAccountSignin-Email-EnsureAccountActivated 技术资料相关联的页面定义的每种受支持语言定义the localized strings:
<BuildingBlocks>
...
<Localization>
<SupportedLanguages />
<LocalizedResources Id="api.signuporsignin.en">
<LocalizedStrings>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfClaimsTransformationBooleanValueIsNotEqual">Whoops, your e-mail address hasn't been verified, contact Support.</LocalizedString>
</LocalizedStrings>
</LocalizedResources>
<LocalizedResources Id="api.signuporsignin.es">
<LocalizedStrings>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfClaimsTransformationBooleanValueIsNotEqual">Vaya, su dirección de correo electrónico no ha sido verificada, contacte a Soporte.</LocalizedString>
</LocalizedStrings>
</LocalizedResources>
</Localization>
</BuildingBlocks>
(如果翻译不正确,我不会说西班牙语,很抱歉。)
最后一步是从页面定义到本地化资源declare references:
<BuildingBlocks>
...
<ContentDefinitions>
<ContentDefinition Id="api.signuporsignin">
...
<LocalizedResourcesReferences MergeBehavior="Prepend">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.signuporsignin.en" />
<LocalizedResourcesReference Language="es" LocalizedResourcesReferenceId="api.signuporsignin.es" />
</LocalizedResourcesReferences>
</ContentDefinition>
</ContentDefinitions>
<Localization />
</BuildingBlocks>