oauth2.0 .NET 6:SignOutAsync,具有相同cookie的后续请求将进行身份验证

pqwbnv8z  于 2023-08-02  发布在  .NET
关注(0)|答案(1)|浏览(108)

我有一个使用react和.NET Core和OAuth的应用程序。
在登录时,我执行

HttpContext.SignInAsync("Cookies", claimsPrincipalWithClaims, authProps)

字符串
我一签字就跑

httpContext.SignOutAsync("Cookies")


我退出了UI,但是当我在postman中复制请求时,我仍然可以得到200-我仍然可以得到200,直到会话到期。
在注销后的后续请求中,User.Identity.IsAuthenticated仍然为true。
每个端点都用[Authorize]修饰,但仍然返回200 post logout。
注销端点返回Set-Cookie标头,其中包含:
.AspNetCore.Cookies=; expites Thu, 01 Jan 1970 GMP; path=/; secure; samesite=string; httponly;
这会杀死应用程序连接,但服务器端-会话仍然存在。
我错过了什么明显的吗?

vmdwslir

vmdwslir1#

虽然,你还没有公布你是如何以及在哪里调用httpContext.SignOutAsync("Cookies")的,但我假设,你可能在你的方法中缺少了asyncawait,这可能是导致这种行为的原因。
你能试试下面的方法吗?

[HttpGet]
public async Task Logout()
{
    // To sign out the current user and delete their cookie, call SignOutAsync:
    await HttpContext.SignOutAsync("Cookies", new AuthenticationProperties { RedirectUri = "/" });
}

字符串

相关问题