Azure AD B2C Configure Multiple Sign on Policies

时光毁灭记忆、已成空白 提交于 2019-12-24 10:26:37

问题


I would like to implement multiple sign up/sign in policies in Azure AD B2C similar to this question but I don't know how to configure my solution in Visual Studio to reference the different signup policies specified in the web.config file. Can anyone help please?


回答1:


You can invoke a different policy for a different type of user by 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();
}

and then 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;
}


来源:https://stackoverflow.com/questions/53065157/azure-ad-b2c-configure-multiple-sign-on-policies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!