C
C#2y ago
PontiacGTX

❔ Invalidating Claims from previous sessions claims when Logging In

I am using ASP.NET Core 2.0 AND IdentityServer(4?) and I need to invalidate the previous login when this user logins but I see that calling UpdateSecurityStampAsync logs me out from all previous login even tho I make it login once more...(this event is called everytime it logins but i dont know hwo ot invalidate the previous logins, do you mind helping me? thank you
o.Events.OnSigningIn = async ctx =>
{
Console.WriteLine("SignIn");
var principal = ctx.Principal;
if ((ctx.Principal?.Identity is ClaimsIdentity claimIdentity))
{
var mgr = ctx.HttpContext.RequestServices.GetRequiredService<SignInManager<ApplicationUser>>();
var user = await mgr.UserManager.FindByNameAsync(claimIdentity.Name);
var res =mgr.UserManager.UpdateSecurityStampAsync(user).Result;
if(res.Succeeded)
{
if(!mgr.IsSignedIn(ctx.Principal))
await mgr.SignInAsync(user, true);
}

}

};
o.Events.OnSigningIn = async ctx =>
{
Console.WriteLine("SignIn");
var principal = ctx.Principal;
if ((ctx.Principal?.Identity is ClaimsIdentity claimIdentity))
{
var mgr = ctx.HttpContext.RequestServices.GetRequiredService<SignInManager<ApplicationUser>>();
var user = await mgr.UserManager.FindByNameAsync(claimIdentity.Name);
var res =mgr.UserManager.UpdateSecurityStampAsync(user).Result;
if(res.Succeeded)
{
if(!mgr.IsSignedIn(ctx.Principal))
await mgr.SignInAsync(user, true);
}

}

};
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.