Created
March 7, 2014 14:22
-
-
Save khalidabuhakmeh/9412344 to your computer and use it in GitHub Desktop.
Refresh Claims for AuthenticationManager OWIN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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