Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top