Azure AD B2C配置多个登录策略

时间:2018-10-30 13:16:49

标签: azure azure-ad-b2c

我想在Azure AD B2C中实现类似于this question的多个注册/登录策略,但是我不知道如何在Visual Studio中配置我的解决方案以引用Web中指定的不同注册策略.config文件。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您可以通过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;
}
相关问题