Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created March 7, 2014 14:22
Show Gist options
  • Select an option

  • Save khalidabuhakmeh/9412344 to your computer and use it in GitHub Desktop.

Select an option

Save khalidabuhakmeh/9412344 to your computer and use it in GitHub Desktop.
Refresh Claims for AuthenticationManager OWIN
public async Task Refresh(ClaimsIdentity claim, bool? rememberMe)
{
var current = _authenticationManager.User;
var remember = current.Claims.FirstOrDefault(x => x.Type == ClaimTypes.IsPersistent);
if (rememberMe.HasValue) {
// remember the "remember me" :)
claim.AddClaim(new Claim(ClaimTypes.IsPersistent, rememberMe.ToString()));
}
else if (claim != null) {
claim.AddClaim(remember);
rememberMe = bool.Parse(remember.Value);
}
else {
rememberMe = false;
claim.AddClaim(new Claim(ClaimTypes.IsPersistent, rememberMe.ToString()));
}
_authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
_authenticationManager.SignIn(new AuthenticationProperties {
IsPersistent = rememberMe.Value
}, claim);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment