Azure AD B2C 配置多重登录策略

标签 azure azure-ad-b2c

我想在 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/

相关文章:

azure - 配置 Azure ContainerInstance 以使用自托管注册表

visual-studio-2010 - Azure SDK 1.5安装错误

asp.net - 使用 .NET Core 2 的 Azure AD B2C Web API

Azure AD v2 登录的 JavaScript OAuth2 流不提供 access_token

azure - Azure Active Directory B2C 是否可以与 Oauth 或 Open ID 配合使用?

asp.net - Release模式下 swagger 文件出现问题

azure - 如何防止通过 Put Blob 将大文件上传到 Azure

azure - 将 Spark ML 模型保存在 azure blob 中

使用刷新 token 的 Azure Active Directory B2C 定价说明

azure - Azure AD B2C 是否允许在自定义域登录页面而不是 https ://<tenant-name>. b2clogin.com 页面上登录?