C# net core/IdentityServer:无法注销

C# net core/IdentityServer:无法注销,c#,.net-core,asp.net-identity,asp.net-core-webapi,identityserver4,C#,.net Core,Asp.net Identity,Asp.net Core Webapi,Identityserver4,在我的Blazor应用程序中,我使用Identity server(Identity server.io)作为外部服务来管理授权 登录正常,但当我尝试注销,然后尝试登录时,我直接登录,不需要任何用户名/pwd!我已经搜索了一个星期了,没有找到任何解决方案 我使用以下代码: var props = (returnUrl is null) ? null : new AuthenticationProperties() { RedirectUri = returnUrl

在我的Blazor应用程序中,我使用Identity server(Identity server.io)作为外部服务来管理授权

登录正常,但当我尝试注销,然后尝试登录时,我直接登录,不需要任何用户名/pwd!我已经搜索了一个星期了,没有找到任何解决方案

我使用以下代码:

    var props = (returnUrl is null) ? null : new AuthenticationProperties()
    {
        RedirectUri = returnUrl
    };

    await HttpContext.SignOutAsync("Cookies");
    await HttpContext.SignOutAsync("oidc", props);
我也尝试删除所有cookie,但是HttpContext.Request.cookies没有cookie

我还查看了以下链接: 但我看不出有什么帮助

仅供参考,以下是我的设置方式:

private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
        {
            context.Services.AddAuthentication(options =>
                {
                    options.DefaultScheme = "Cookies";
                    options.DefaultChallengeScheme = "oidc";
                })
                .AddCookie("Cookies", options =>
                {
                    options.ExpireTimeSpan = TimeSpan.FromDays(365);
                    //options.Cookie.Name = ".MyApp";
                })
                .AddOpenIdConnect("oidc", options =>
                {
                    options.Authority = configuration["AuthServer:Authority"];
                    options.RequireHttpsMetadata = true;
                    options.ResponseType = OpenIdConnectResponseType.CodeIdToken;

                    options.ClientId = configuration["AuthServer:ClientId"];
                    options.ClientSecret = configuration["AuthServer:ClientSecret"];

                    options.SaveTokens = true;
                    options.GetClaimsFromUserInfoEndpoint = true;

                    options.Scope.Add("role");
                    options.Scope.Add("email");
                    options.Scope.Add("phone");
                    options.Scope.Add("MyApp");

                    options.ClaimActions.MapAbpClaimTypes();
                });
        }

要在从IDS4注销后重定向回您的客户端应用程序,请单击链接
单击此处返回到交互式客户端…
,您应在客户端配置中设置正确的
PostLogoutRedirecuturis

new Client
{
    ....

    // where to redirect to after logout
    PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },

     ....
}, 

在@McGuireV10的文章中,他正在使用identity server的演示服务器进行测试,并使用
interactive.confidential.short
客户端,您无法设置该客户端的
PostlogoutRedirecuturis
,因此它将是
https://localhost:5001/signout-默认情况下,回调oidc
。您可以设置自己的identity server来测试场景。

要在从IDS4注销后重定向回您的客户端应用程序,请单击链接
,单击此处返回交互式客户端…
,您应该在客户端配置中设置正确的
PostLogoutRectori

new Client
{
    ....

    // where to redirect to after logout
    PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },

     ....
}, 

在@McGuireV10的文章中,他正在使用identity server的演示服务器进行测试,并使用
interactive.confidential.short
客户端,您无法设置该客户端的
PostlogoutRedirecuturis
,因此它将是
https://localhost:5001/signout-默认情况下,回调oidc
。您可以设置自己的identity server来测试该场景。

您没有提到是使用Blazor客户端还是服务器端,但我最近用Blazor写了一篇关于服务器端OIDC的文章:(以及之后的几篇相关文章)。非常感谢@McGuireV10,您的示例帮助,我正在研究这个问题。但我注意到,在您的示例中,当我们注销时,我们不会重定向到所需的页面,而是停留在identity server上。举例来说,如果我想重定向到一个“index.html”页面,我该怎么做?谢谢你没有提到你是在使用Blazor客户端还是服务器端,但我最近写了一篇关于Blazor的服务器端OIDC的文章:(以及之后的几篇相关文章)。谢谢@McGuireV10,你的示例帮助很大,我正在做这件事。但我注意到,在您的示例中,当我们注销时,我们不会重定向到所需的页面,而是停留在identity server上。举例来说,如果我想重定向到一个“index.html”页面,我该怎么做?谢谢我尝试了PostLogoutRedirectUris,我将其设置为,但它不起作用。我还尝试返回新的重定向结果(“/index.html”),但是我被重定向了,但没有注销!在Identity serverHi@NanYu中注销后,请挂上链接确认url,这是什么意思?我将PostLogoutRedirectUris设置为正确的URL,但它似乎确实有效!有没有调试的想法?在客户端应用程序中单击注销后,用户将重定向到Identity server的注销页面,有一个href链接显示
单击此处返回交互式客户端…
,当单击此处
时,用户将再次重定向到客户端应用程序,
PostLogoutRedirectUris
就是这个url。检查该url并查看它是否与您的客户端应用程序匹配我尝试了PostLogoutRedirectUris,我将其设置为,但它不起作用。我还尝试返回新的重定向结果(“/index.html”),但是我被重定向了,但没有注销!在Identity serverHi@NanYu中注销后,请挂上链接确认url,这是什么意思?我将PostLogoutRedirectUris设置为正确的URL,但它似乎确实有效!有没有调试的想法?在客户端应用程序中单击注销后,用户将重定向到Identity server的注销页面,有一个href链接显示
单击此处返回交互式客户端…
,当单击此处
时,用户将再次重定向到客户端应用程序,
PostLogoutRedirectUris
就是这个url。检查该url并查看它是否与您的客户端应用程序匹配