我想在 Azure AD B2C 中实现多个注册/登录策略,类似于 this question但我不知道如何在 Visual Studio 中配置我的解决方案以引用 web.config 文件中指定的不同注册策略。有人可以帮忙吗?
最佳答案
您可以通过passing the requested policy from a controller method to the authentication middleware为不同类型的用户调用不同的策略。 :
public IActionResult LogInForIndividualCustomer()
{
return LogInFor(Constants.AuthenticationSchemes.B2COpenIdConnect, Constants.Policies.SignUpOrSignInWithPersonalAccount);
}
private IActionResult LogInFor(string authenticationScheme, string policy)
{
if (!User.Identity.IsAuthenticated)
{
return new ChallengeResult(
authenticationScheme,
new AuthenticationProperties(
new Dictionary<string, string>
{
{Constants.AuthenticationProperties.Policy, policy}
})
{
RedirectUri = Url.Action("LoggedIn", "Account", values: null, protocol: Request.Scheme)
});
}
return RedirectToHome();
}
然后setting the redirection URL for the requested policy in the authentication middleware :
OnRedirectToIdentityProvider = async context =>
{
var policy = context.Properties.Items.ContainsKey(Constants.AuthenticationProperties.Policy) ? context.Properties.Items[Constants.AuthenticationProperties.Policy] : Constants.Policies.SignUpOrSignInWithPersonalAccount;
var configuration = await GetB2COpenIdConnectConfigurationAsync(context, policy);
context.ProtocolMessage.IssuerAddress = configuration.AuthorizationEndpoint;
}
关于Azure AD B2C 配置多重登录策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53065157/