private static void AddOrUpdateClaims(User user, ClaimsPrincipal UserClaimsPrincipal) { var existingPasswordIsAboutToExpireClaim = ClaimHelper.GetClaim(UserClaimsPrincipal, CustomClaimTypes.PasswordIsAboutToExpire); if (existingPasswordIsAboutToExpireClaim != null) { ((ClaimsIdentity)UserClaimsPrincipal.Identity).RemoveClaim(existingPasswordIsAboutToExpireClaim); } ((ClaimsIdentity)UserClaimsPrincipal.Identity).AddClaim(new Claim(CustomClaimTypes.PasswordIsAboutToExpire, JsonConvert.SerializeObject(user.PasswordIsAboutToExpire))); var existingPasswordExpiryDaysRemaining = ClaimHelper.GetClaim(UserClaimsPrincipal, CustomClaimTypes.PasswordExpiryDaysRemaining); if (existingPasswordExpiryDaysRemaining != null) { ((ClaimsIdentity)UserClaimsPrincipal.Identity).RemoveClaim(existingPasswordExpiryDaysRemaining); } ((ClaimsIdentity)UserClaimsPrincipal.Identity).AddClaim( new Claim(CustomClaimTypes.PasswordExpiryDaysRemaining, JsonConvert.SerializeObject(user.PasswordExpiryDaysRemaining))); }
public void GetClaim() { const string CliamType = "key"; var claims = new[] { new Claim(CliamType, "value") }; var claim = ClaimHelper.GetClaim(new ClaimsPrincipal(new ClaimsIdentity(claims)), CliamType); claim.Should().NotBeNull(); claim.Should().BeOfType(typeof(Claim)); }
public async Task <IActionResult> Get([FromQuery] bool?lastest) { var userinformation = ClaimHelper.GetClaim(User.Identity as ClaimsIdentity); var result = await _brushingInformationService .Get(lastest, userinformation.UserId.ToString()) .ConfigureAwait(false); return(Ok(result)); }
public async Task <IActionResult> Get() { var userinformation = ClaimHelper.GetClaim(User.Identity as ClaimsIdentity); var result = await _sleepInformationService .Get(x => x.UserId == userinformation.UserId.ToString()) .ConfigureAwait(false); return(Ok(result)); }
public async Task <IActionResult> ManageInformation(BrushingInformation brushingInformation) { var userinformation = ClaimHelper.GetClaim(User.Identity as ClaimsIdentity); brushingInformation.UserId = userinformation.UserId.ToString(); var result = await _brushingInformationService .ManageInformation(brushingInformation) .ConfigureAwait(false); return(Ok(result)); }
public async Task <IActionResult> GetPhoneRanking( [FromQuery] string name, [FromQuery] string os, [FromQuery] int?page, [FromQuery] int?pagesize) { var userinformation = ClaimHelper.GetClaim(User.Identity as ClaimsIdentity); var result = await _phoneRankingService.GetPhoneRanking(userinformation.UserId, name, os, page, pagesize).ConfigureAwait(false); return(Ok(result)); }
public void GetClaim_CheckForInvaldClaim() { ClaimHelper.GetClaim(new ClaimsPrincipal(), null); }
public void GetClaim_CheckArgumentNullException() { ClaimHelper.GetClaim(null, null); }