On a MVC5 web app I'm using Asp.net Identity. When the user register, I add some claims, they are saved on the database and restored when the user log in. This works perfectly. Now, based on a parameter (a checkbox on the login page), I want to, when the user login add a specific Claim to the user. But there is a catch: this Claim will only exist on that user specific session (if the same user log on another browser instance or device and do not check the checkbox, he wont have that claim). I am not using and wish not to rely on asp.net Session.
I implemented this easily, just adding the Claim when calling AuthenticationManager.SignIn
:
private async Task SignInAsync(CustomUser user, bool isPersistent, bool myCustomTemporaryClaim)
{
var identities = await user.GenerateUserIdentityAsync(UserManager);
if (myCustomTemporaryClaim)
{
identities.AddClaim(new Claim(CustomClaimTypes.MyCustomTemporaryClaim, "true"));
}
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identities);
}
This works fine. But the default asp.net identity implementation that comes on the VS template is configured to "refresh" the identity every 30 minutes. When this happens, I loose my Custom claim. So, what I would like to know is, it is possible to "intercept" and get my custom claim value before asp.net identity re-generate the cookie?
I can just remove the regenerateIdentityCallback
but I do not know what the outcome of this may be.