【发布时间】:2021-05-03 10:08:57
【问题描述】:
我为 Azure AD B2C 上的注册创建了一个自定义策略,目的是只允许电子邮件被列入白名单的用户能够注册到系统中。
为此,我使用 REST 技术配置文件配置了自定义策略。
关联的网络服务接收想要注册的用户的电子邮件,并验证该用户的电子邮件地址是否在已列入白名单的电子邮件列表中。如果不是,我会返回以下格式的消息:
{
"userMessage": "Sorry, this email is not whitelisted",
"status": 409,
"version": "1.0.0"
}
如果电子邮件是白名单的一部分,我会返回:
{
"emailValue": "myemail@email.com",
"isWhiteListed": true
}
这是我的用户旅程的样子(在 Signup.xml 文件中):
<UserJourneys>
<UserJourney Id="SignUp">
<OrchestrationSteps>
<OrchestrationStep Order="1" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="SignUpWithLogonEmailExchange" TechnicalProfileReferenceId="LocalAccountSignUpWithLogonEmail" />
</ClaimsExchanges>
</OrchestrationStep>
<!-- This step reads any user attributes that we may not have received when in the token. -->
<OrchestrationStep Order="2" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="AADUserReadWithObjectId" TechnicalProfileReferenceId="AAD-UserReadUsingObjectId" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="3" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="RESTEmailWhitelist" TechnicalProfileReferenceId="REST-EmailWhitelist" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="4" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />
</OrchestrationSteps>
<ClientDefinition ReferenceId="DefaultWeb" />
</UserJourney>
</UserJourneys>
问题是,即使在返回 409 错误以防电子邮件未列入白名单后,它仍然在 Azure AD B2C 中成功创建。
如何防止用户的帐户被成功创建?
【问题讨论】:
-
您返回的响应格式是完美的,但请确认您的api是否返回400/409作为响应码。
-
我遇到了同样的问题。我按照文档的建议返回 409 和 version 和 userMessage,但自定义策略不尊重它。
标签: azure azure-active-directory azure-ad-b2c azure-ad-b2c-custom-policy