public ClaimsPrincipal GetClaimsPrincipal(IUser user) { if (user is null) { return(null); } var userClaims = new List <Claim> { new Claim(ClaimTypes.Name, user.DisplayName), new Claim(ClaimTypes.NameIdentifier, user.Username), new Claim(ClaimTypes.Email, user.Email) }; if (user.IsAdmin) { userClaims.Add(new Claim(ClaimTypes.Role, "Admin")); } var claimsIdentity = new ClaimsIdentity(userClaims, _authenticationService.GetType().Name); return(new ClaimsPrincipal(claimsIdentity)); }
public new ClaimsPrincipal GetClaimsPrincipal(IUser user) { var claimsPrincipal = base.GetClaimsPrincipal(user); if (claimsPrincipal is null) { return(null); } if (user.IsDeveloper && !claimsPrincipal.HasClaim(c => c.Type == ClaimTypes.Role)) { var userClaims = new List <Claim> { new Claim(ClaimTypes.Role, "Admin"), }; var claimsIdentity = new ClaimsIdentity(userClaims, _authenticationService.GetType().Name); claimsPrincipal.AddIdentity(claimsIdentity); } return(claimsPrincipal); }