c# - 网络核心/身份服务器: unable to logout

标签 c# .net-core asp.net-identity asp.net-core-webapi identityserver4

在我的 Blazor 应用中,我使用身份服务器 (identityserver.io) 作为外部服务来管理授权。

登录工作正常,但是当我尝试注销,然后尝试登录时,我直接登录,而不询问任何用户名/密码!我已经搜索了一个星期了,但没有找到任何解决方案!

我使用以下代码:

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

    await HttpContext.SignOutAsync("Cookies");
    await HttpContext.SignOutAsync("oidc", props);

我也尝试删除所有cookie,但HttpContext.Request.Cookies没有cookie!

我还检查了以下链接: https://mcguirev10.com/2018/01/26/signoutasync-and-identity-server-cookies.html 但我没有看到任何有帮助的!

仅供引用,这是我的设置方法:

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 注销后通过单击链接Click here to return to the Interactive client .... 重定向回您的客户端应用程序,您应该在中设置正确的 PostLogoutRedirectUris客户端配置:

new Client
{
    ....

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

     ....
}, 

在@McGuireV10的文章中,他使用身份服务器的演示服务器进行测试,并使用interactive.confidential.short客户端,您无法设置该客户端的PostLogoutRedirectUris ,因此默认为 https://localhost:5001/signout-callback-oidc 。您可以设置自己的身份服务器来测试场景。

关于c# - 网络核心/身份服务器: unable to logout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59486045/

相关文章:

.net-core - 结合 .NET Core 2.2 和 3.0 项目

asp.net-identity - 更改 IdentityServerAuthenticationOptions 客户端上的 ApiName 后仍然可以使用 Identity Server 4

c# - C# 中的存储库模式

c# - 无法加载文件或程序集 System.Net.Http 版本 4.1.1.0

c# - 使用 "generic value"将对象转换为 KeyValuePair?

.net-core - HttpClient.SendAsync() 未将 JSON 作为字符串发送

asp.net-mvc - AuthenticationManager.SignIn 上的 HttpContext.Current.User.Identity

c# - 在 ASP.NET 的 IdentityUserRole 2.0 中获取角色名称

c#对象到字符串以文本格式显示它

使用 SpecFlow 时,C# NUnit SetUp 和 TearDown 函数未运行