public IActionResult Get() { //Get Roles for current user var roles = ClaimsHelper.GetValues <string>((ClaimsIdentity)User.Identity, "role"); return(Ok($"Current user ({User.Identity.Name}) have following roles: {string.Join("|", roles)}")); }
protected override string Handle(GetRolesRequest request) { var user = _httpContextAccessor.HttpContext.User; var roles = ClaimsHelper.GetValues <string>((ClaimsIdentity)user.Identity, "role"); return($"Current user ({user.Identity.Name}) have following roles: {string.Join("|", roles)}"); }
/// <inheritdoc /> public ApplicationUserMapperConfiguration() { CreateMap <RegisterViewModel, ApplicationUser>() .ForMember(x => x.UserName, o => o.MapFrom(p => p.Email)) .ForMember(x => x.Email, o => o.MapFrom(p => p.Email)) .ForMember(x => x.EmailConfirmed, o => o.MapFrom(src => true)) .ForMember(x => x.FirstName, o => o.MapFrom(p => p.FirstName)) .ForMember(x => x.LastName, o => o.MapFrom(p => p.LastName)) .ForMember(x => x.PhoneNumberConfirmed, o => o.MapFrom(src => true)) .ForAllOtherMembers(x => x.Ignore()); CreateMap <ClaimsIdentity, ApplicationUserProfileViewModel>() .ForMember(x => x.Id, o => o.MapFrom(claims => ClaimsHelper.GetValue <Guid>(claims, JwtClaimTypes.Subject))) .ForMember(x => x.PositionName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, ClaimTypes.Actor))) .ForMember(x => x.FirstName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.GivenName))) .ForMember(x => x.LastName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, ClaimTypes.Surname))) .ForMember(x => x.Roles, o => o.MapFrom(claims => ClaimsHelper.GetValues <string>(claims, JwtClaimTypes.Role))) .ForMember(x => x.Email, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.Name))) .ForMember(x => x.EmailVerified, o => o.MapFrom(claims => ClaimsHelper.GetValue <bool>(claims, JwtClaimTypes.EmailVerified))) .ForMember(x => x.PreferredUserName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.PreferredUserName))) .ForMember(x => x.PhoneNumber, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.PhoneNumber))) .ForMember(x => x.PhoneNumberVerified, o => o.MapFrom(claims => ClaimsHelper.GetValue <bool>(claims, JwtClaimTypes.PhoneNumberVerified))) .ForMember(x => x.AdditionalEmails, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, "AdditionalEmails"))) .ForAllOtherMembers(x => x.Ignore()); }
/// <inheritdoc /> public ProfilesMapperConfiguration() { CreateMap <RegisterViewModel, ApplicationUser>() .ForMember(x => x.UserName, o => o.MapFrom(p => p.Email)) .ForMember(x => x.Email, o => o.MapFrom(p => p.Email)) .ForMember(x => x.EmailConfirmed, o => o.MapFrom(src => true)) .ForMember(x => x.FirstName, o => o.MapFrom(p => p.FirstName)) .ForMember(x => x.LastName, o => o.MapFrom(p => p.LastName)) .ForMember(x => x.PhoneNumberConfirmed, o => o.MapFrom(src => true)) .ForMember(x => x.ApplicationUserProfileId, o => o.Ignore()) .ForMember(x => x.ApplicationUserProfile, o => o.Ignore()) .ForMember(x => x.Id, o => o.Ignore()) .ForMember(x => x.NormalizedUserName, o => o.Ignore()) .ForMember(x => x.NormalizedEmail, o => o.Ignore()) .ForMember(x => x.PasswordHash, o => o.Ignore()) .ForMember(x => x.SecurityStamp, o => o.Ignore()) .ForMember(x => x.ConcurrencyStamp, o => o.Ignore()) .ForMember(x => x.PhoneNumber, o => o.Ignore()) .ForMember(x => x.TwoFactorEnabled, o => o.Ignore()) .ForMember(x => x.LockoutEnd, o => o.Ignore()) .ForMember(x => x.LockoutEnabled, o => o.Ignore()) .ForMember(x => x.AccessFailedCount, o => o.Ignore()); CreateMap <ClaimsIdentity, UserProfileViewModel>() .ForMember(x => x.Id, o => o.MapFrom(claims => ClaimsHelper.GetValue <Guid>(claims, JwtClaimTypes.Subject))) .ForMember(x => x.PositionName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, ClaimTypes.Actor))) .ForMember(x => x.FirstName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.GivenName))) .ForMember(x => x.LastName, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, ClaimTypes.Surname))) .ForMember(x => x.Roles, o => o.MapFrom(claims => ClaimsHelper.GetValues <string>(claims, JwtClaimTypes.Role))) .ForMember(x => x.Email, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.Name))) .ForMember(x => x.PhoneNumber, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.PhoneNumber))); }
.ForMember(x => x.Roles, o => o.MapFrom(claims => ClaimsHelper.GetValues <string>(claims, JwtClaimTypes.Role))) .ForMember(x => x.Email, o => o.MapFrom(claims => ClaimsHelper.GetValue <string>(claims, JwtClaimTypes.Name)))