Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Claims after user login

Is it possible to update claims after user login? I have frontend and admin panel in my site, basically I'm using claims to achieve this. If a user is logged in as Susan in frontend, I did something like this in my code :

var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

userIdentity.AddClaim(new Claim("Id", this.UserName));
... //other claims here

So when user finally login on admin panel (when still logged on in frontend), I just want to add more claims for example :

userIdentity.AddClaim(new Claim("BackEndId", this.UserName));

How to achieve this?

like image 314
warheat1990 Avatar asked Sep 15 '25 20:09

warheat1990


1 Answers

To be able to read the claim on a cookie you need to sign user our and sign them back in again during the same request:

idenityt.AddClaim(new Claim("myClaimType", "myClaimValue"));

var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, idenityt);
like image 55
trailmax Avatar answered Sep 18 '25 16:09

trailmax