services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
var allowed = options.User.AllowedUserNameCharacters + "ęóąśłżźćń";
options.User.AllowedUserNameCharacters = allowed;
}).AddEntityFrameworkStores<DomainModelContext>()
.AddRoles<ApplicationRole>()
.AddClaimsPrincipalFactory<ApplicationClaimsIdentityFactory>()
.AddDefaultTokenProviders();
public class ApplicationClaimsIdentityFactory : UserClaimsPrincipalFactory<ApplicationUser, ApplicationRole>
{
private readonly IHttpContextAccessor _httpContext;
public ApplicationClaimsIdentityFactory(UserManager<ApplicationUser> userManager, RoleManager<ApplicationRole> roleManager, IOptions<IdentityOptions> options, IHttpContextAccessor httpContext) : base(userManager, roleManager, options)
{
_httpContext = httpContext;
}
public override async Task<System.Security.Claims.ClaimsPrincipal> CreateAsync(ApplicationUser user)
{
ClaimsPrincipal principal = await base.CreateAsync(user);
ClaimsIdentity claimsIdentity = (ClaimsIdentity)principal.Identity;
var ddd = claimsIdentity.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/name");
foreach (var dd in ddd) {
claimsIdentity.RemoveClaim(dd);
}
//claimsIdentity.Claims.ToList().RemoveAt(30);
//claimsIdentity.Claims.Where(x => x.Type == )
//claimsIdentity.AddClaim(new Claim("Deleted", user.Deleted.ToString().ToLower()));
//_httpContext.HttpContext.User = principal;
return principal;
}
}