Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I modify claims in ASP.NET Identity with OWIN after calling SignIn?

Is is possible to retrieve and modify claims in a controller after SignIn has been called? This doesn't work for me:

ClaimsIdentity i = (ClaimsIdentity)HttpContext.GetOwinContext().Authentication.User.Identity;
i.AddClaim(new Claim("type", "value"));

What I need to do is: after login is complete and the user has been doing other things, they POST a form and I need to modify the claims at this point and redirect them to another page. I wonder if this isn't working due to PRG and cookies, or just Identity, or my lack of knowledge?

Update: I actually worked around this by calling SignIn a second time, which seems to work, but I would guess that has side-effects so it would be nice to know if there is a way to modify these regardless.

like image 339
Josh Avatar asked Mar 31 '14 18:03

Josh


1 Answers

Calling SignIn is exactly what you are supposed to do when you want to modify the claims for the user. It basically causes the ClaimsIdentity to be serialized into the cookie, which is why you see the new claims show up on subsequent requests.

like image 180
Hao Kung Avatar answered Oct 13 '22 01:10

Hao Kung