❔ how to logout specific user with identityserver
I am trying to logout an specific user from previous identity user sessions, so what could I do to specifically logout one user when it logins?
2 Replies
I tried the following
try
{
var sessionclaims = User.Claims.ToList();
var claims = await _userManager.GetClaimsAsync(u);
var session = claims.Where(e => e.Type == "session");
IdentityResult res = null;
var siteCookies = HttpContext.Request.Cookies.Where(c => c.Key.Contains(".AspNetCore.") || c.Key.Contains("Microsoft.Authentication") || c.Key.Contains("IdentityServer.Cookie") || c.Key.Contains("idsrv.session")).ToList();
foreach (var cookie in siteCookies)
{
Response.Cookies.Delete(cookie.Key);
}
await HttpContext.SignOutAsync("idsrv");
await HttpContext.SignOutAsync("Identity.Application");
await HttpContext.SignOutAsync(IdentityServerConstants.DefaultCookieAuthenticationScheme);
await _signInManager.SignOutAsync();
if (session.Any())
await _userManager.RemoveClaimsAsync(u, session);
}
catch (Exception ex)
{
}
try
{
var sessionclaims = User.Claims.ToList();
var claims = await _userManager.GetClaimsAsync(u);
var session = claims.Where(e => e.Type == "session");
IdentityResult res = null;
var siteCookies = HttpContext.Request.Cookies.Where(c => c.Key.Contains(".AspNetCore.") || c.Key.Contains("Microsoft.Authentication") || c.Key.Contains("IdentityServer.Cookie") || c.Key.Contains("idsrv.session")).ToList();
foreach (var cookie in siteCookies)
{
Response.Cookies.Delete(cookie.Key);
}
await HttpContext.SignOutAsync("idsrv");
await HttpContext.SignOutAsync("Identity.Application");
await HttpContext.SignOutAsync(IdentityServerConstants.DefaultCookieAuthenticationScheme);
await _signInManager.SignOutAsync();
if (session.Any())
await _userManager.RemoveClaimsAsync(u, session);
}
catch (Exception ex)
{
}
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.