Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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
C# Asp.NET 4.7.2多个Owin身份验证提供程序_C#_Asp.net_Owin - Fatal编程技术网

C# Asp.NET 4.7.2多个Owin身份验证提供程序

C# Asp.NET 4.7.2多个Owin身份验证提供程序,c#,asp.net,owin,C#,Asp.net,Owin,是否可以在同一个应用程序中使用两个OpenIdConnect提供程序?我需要为两个不同的组登录,第一个是拥有有效Azure AD帐户的员工,第二个是没有Azure AD帐户的客户。我知道要使用的端点,并使用.NET Core开发过包含此功能的应用程序,但我无法在.NET 4.7.2中成功实现此功能 在我的start.auth.cs文件中,我一直在尝试添加如下提供程序 app.UseOpenIdConnectAuthentication(CustomerOptions()); app.UseOpe

是否可以在同一个应用程序中使用两个OpenIdConnect提供程序?我需要为两个不同的组登录,第一个是拥有有效Azure AD帐户的员工,第二个是没有Azure AD帐户的客户。我知道要使用的端点,并使用.NET Core开发过包含此功能的应用程序,但我无法在.NET 4.7.2中成功实现此功能

在我的start.auth.cs文件中,我一直在尝试添加如下提供程序

app.UseOpenIdConnectAuthentication(CustomerOptions());
app.UseOpenIdConnectAuthentication(EmployeeOptions());

    private static OpenIdConnectAuthenticationOptions EmployeeOptions() =>
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = ClientId,
                Authority = authority,
                RedirectUri = RedirectUri,
                ClientSecret = ClientSecret,
                PostLogoutRedirectUri = RedirectUri,
                Scope = OpenIdConnectScope.OpenIdProfile,
                // ResponseType is set to request the id_token - which contains basic information about the signed-in user
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
                // ValidateIssuer set to false to allow personal and work accounts from any organization to sign in to your application
                // To only allow users from a single organizations, set ValidateIssuer to true and 'tenant' setting in web.config to the tenant name
                // To allow users from only a list of specific organizations, set ValidateIssuer to true and use ValidIssuers parameter
                TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = false // This is a simplification
                },
                // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthenticationFailed = OnAuthenticationFailed,
                    SecurityTokenValidated = OnAdSecurityTokenValidated
                }
            };
其中…Options方法具有特定于每个端点的OpenIdConnectAuthenticationOptions。如果我只使用其中一种方法,我可以在应用程序中进行身份验证,但当我尝试添加这两种方法时,身份验证将只使用最后添加的客户端

调用这些方法的代码是: 1.调用Azure广告提供商

            HttpContext.GetOwinContext().Authentication.Challenge(
                new AuthenticationProperties { RedirectUri = "/" },
                OpenIdConnectAuthenticationDefaults.AuthenticationType);
打电话给客户提供商

        var properties = new AuthenticationProperties { RedirectUri = "/" };
        var scheme = "schemeName";
        HttpContext.GetOwinContext().Authentication.Challenge(properties, scheme);
如何调用适当的身份验证提供程序


谢谢

我在更新OpenIdConnectAuthenticationOptions时忽略了设置authentication type参数,因此在添加第二个身份验证提供程序时覆盖了默认设置

app.UseOpenIdConnectAuthentication(CustomerOptions());
app.UseOpenIdConnectAuthentication(EmployeeOptions());

private static OpenIdConnectAuthenticationOptions EmployeeOptions() =>
        new OpenIdConnectAuthenticationOptions("employeeAuthenticationType")
        {
            ClientId = ClientId,
            Authority = authority,
            RedirectUri = RedirectUri,
            ClientSecret = ClientSecret,
            PostLogoutRedirectUri = RedirectUri,
            Scope = OpenIdConnectScope.OpenIdProfile,
            // ResponseType is set to request the id_token - which contains basic information about the signed-in user
            ResponseType = OpenIdConnectResponseType.CodeIdToken,
            // ValidateIssuer set to false to allow personal and work accounts from any organization to sign in to your application
            // To only allow users from a single organizations, set ValidateIssuer to true and 'tenant' setting in web.config to the tenant name
            // To allow users from only a list of specific organizations, set ValidateIssuer to true and use ValidIssuers parameter
            TokenValidationParameters = new TokenValidationParameters()
            {
                ValidateIssuer = false // This is a simplification
            },
            // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
            Notifications = new OpenIdConnectAuthenticationNotifications
            {
                AuthenticationFailed = OnAuthenticationFailed,
                SecurityTokenValidated = OnAdSecurityTokenValidated
            }
        };

您需要通过OpenIdConnectAuthenticationOptions.AuthenticationType属性为每个身份验证中间件设置不同的方案,并在质询中传递要验证的方案。。。方法。

您是否设置了OpenIdConnectAuthenticationOptions.AuthenticationType?@Kahbazi-yup,就是这样。如果你想加上这个作为答案,我会把它标记为已回答,这样你就可以拿到赏金了