根据 ASP.NET Core文档 https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie方法HttpContext.Authentication.SignOutAsync()
还必须删除身份验证 cookie。
退出
注销当前用户,并且删除他们的cookie(斜体是我的 - A.C.)在控制器中调用以下命令
await HttpContext.Authentication.SignOutAsync("MyCookieMiddlewareInstance");
但事实并非如此!其他一切似乎都还不错,尤其是。 auth 方案,因为用户正确登录并且 cookie .AspNetCore。被建造。
知道为什么 cookie 在用户退出后仍然保留吗?
你没有发布足够的代码来告诉你,但我怀疑你打电话后SignOutAsync
您有某种类型的重定向(例如,RedirectToAction
),它会覆盖重定向到 OIDC 结束会话 URLSignOutAsync
尝试发出。
(对于重定向覆盖问题给出了相同的解释here https://github.com/aspnet/Security/issues/313#issuecomment-120668602由微软的Haok编写。)
编辑:如果我上面的猜测是正确的,解决方案是在AuthenticationProperties
对象与最终SignOutAsync
:
// in some controller/handler, notice the "bare" Task return value
public async Task LogoutAction()
{
// SomeOtherPage is where we redirect to after signout
await MyCustomSignOut("/SomeOtherPage");
}
// probably in some utility service
public async Task MyCustomSignOut(string redirectUri)
{
// inject the HttpContextAccessor to get "context"
await context.SignOutAsync("Cookies");
var prop = new AuthenticationProperties()
{
RedirectUri = redirectUri
};
// after signout this will redirect to your provided target
await context.SignOutAsync("oidc", prop);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)