/// <summary> /// Called when the security stamp has been verified. By default this /// refreshes the claim principal. /// </summary> /// <remarks> /// The <see cref="Microsoft.AspNetCore.Identity.SecurityStampValidator"/> that this is /// based on refreshed the principal if it is valid. Since the only claim we store that /// changes is the security stamp, this is uneccessary for us, however I'm leaving it in /// as claims refreshing may be required in the future, or if anyone does decide to /// update the <see cref="IClaimsPrincipalFactory"/> to include data that needs to be /// regularly updated. /// </remarks> /// <param name="claimsPrincipalBuilderContext"> /// A context object representing the verified user. This can /// be used to build the refreshed claims principal. /// </param> /// <param name="context">A context object representing the parameters of the cookie validation event.</param> protected virtual async Task ClaimsPrincipalVerifiedAsync(IClaimsPrincipalBuilderContext claimsPrincipalBuilderContext, CookieValidatePrincipalContext validationContext) { var newPrincipal = await _claimsPrincipalFactory.CreateAsync(claimsPrincipalBuilderContext); validationContext.ReplacePrincipal(newPrincipal); validationContext.ShouldRenew = true; if (!validationContext.Options.SlidingExpiration) { // On renewal calculate the new ticket length relative to now to avoid // extending the expiration. validationContext.Properties.IssuedUtc = _dateTimeService.OffsetUtcNow(); } }
public Task <ClaimsPrincipal> CreateAsync(IClaimsPrincipalBuilderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var scheme = AuthenticationSchemeNames.UserArea(context.UserAreaCode); var claims = new[] { new Claim(CofoundryClaimTypes.UserId, Convert.ToString(context.UserId)), new Claim(CofoundryClaimTypes.SecurityStamp, context.SecurityStamp), new Claim(CofoundryClaimTypes.UserAreaCode, context.UserAreaCode), }; var claimsIdentity = new ClaimsIdentity(claims, scheme); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); return(Task.FromResult(claimsPrincipal)); }