Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure 是否有任何方法可以使用多个策略对B2C应用程序进行身份验证_Azure_Asp.net Core_Azure Ad B2c - Fatal编程技术网

Azure 是否有任何方法可以使用多个策略对B2C应用程序进行身份验证

Azure 是否有任何方法可以使用多个策略对B2C应用程序进行身份验证,azure,asp.net-core,azure-ad-b2c,Azure,Asp.net Core,Azure Ad B2c,我使用B2C登录页面来验证我的用户。这些用户根据其业务选择了多个IDP,我用所选IDP创建了多个策略。在基于用户电子邮件的登录页面中,我显示了他的登录页面,其中只有相关的IDP。但在我的web应用程序中,我只能在我的appsettings.json中添加一个注册或登录策略来验证用户。是否有在appsettings.json文件中包含多个策略的选项或任何其他方式来处理此要求 我当前的appsettings.json如下所示 "AzureAdB2C": { "Instance": "https://

我使用B2C登录页面来验证我的用户。这些用户根据其业务选择了多个IDP,我用所选IDP创建了多个策略。在基于用户电子邮件的登录页面中,我显示了他的登录页面,其中只有相关的IDP。但在我的web应用程序中,我只能在我的appsettings.json中添加一个注册或登录策略来验证用户。是否有在appsettings.json文件中包含多个策略的选项或任何其他方式来处理此要求

我当前的appsettings.json如下所示

"AzureAdB2C": {
"Instance": "https://login.microsoftonline.com/tfp/",
"ClientId": "******-***-****-****-*******",
"Domain": "mycustomdomain.onmicrosoft.com",
"SignUpSignInPolicyId": "Org-signinsignout"

},

您可以通过以下方式为不同类型的用户调用不同的策略:

参考:

也请检查这个线程


希望有帮助。

可能重复@MohitVerma MSFT我的要求不同,上面针对不同用户的登录页面和策略是相同的,但我的案例需要不同的登录页面(不同的策略)和不同的IDP。你是否检查了我下面的答案,我也发布了不同策略的答案。这不是您正在寻找的东西吗?当请求到达服务器时,首先我需要验证B2C用户,要进行验证,我需要知道注册或登录策略名称。在这之后,只有我可以阅读声明,我不知道什么是政策。你检查过我上面发布的例子中的这个网站,基本上你需要保持不同的登录选项,当用户点击这些选项时,你需要调用受尊重的政策。
  public IActionResult LogInForBusinessCustomer(string uiLocale)
        {
            return LogInFor(Constants.AuthenticationSchemes.B2COpenIdConnect, Constants.Policies.SignUpOrSignInWithWorkAccount, uiLocale);
        }

    public IActionResult LogInForIndividualCustomer(string uiLocale)
    {
        return LogInFor(Constants.AuthenticationSchemes.B2COpenIdConnect, Constants.Policies.SignUpOrSignInWithPersonalAccount, uiLocale);
    }

    public IActionResult LogInForPartner(string uiLocale)
    {
        return LogInFor(Constants.AuthenticationSchemes.B2BOpenIdConnect, null, uiLocale);
    }

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();
}
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;

                if (context.Properties.Items.ContainsKey(Constants.AuthenticationProperties.UILocales))
                {
                    context.ProtocolMessage.SetParameter("ui_locales", context.Properties.Items[Constants.AuthenticationProperties.UILocales]);
                }

                context.ProtocolMessage.SetParameter("dc", "cdm");
                context.ProtocolMessage.SetParameter("slice", "001-000");
            },