protected override Task HandleRequirementAsync( AuthorizationHandlerContext context, ReportAddEditDelete requirement) { var _userPermissionService = new UserClaimBuilder(context.User); if (_userPermissionService.UserPolicies !.ReportAddEditDelete) { context.Succeed(requirement); } return(Task.CompletedTask); }
protected override Task HandleRequirementAsync( AuthorizationHandlerContext context, RocketAddEditDelete requirement) { var userClaims = new UserClaimBuilder(context.User); if (userClaims.UserPolicies.RocketAddEditDelete) { context.Succeed(requirement); } return(Task.CompletedTask); }
public async Task GetProfileDataAsync(ProfileDataRequestContext context) { var sub = context.Subject.GetSubjectId(); var user = await _userManager.FindByIdAsync(sub); var principal = await _claimsFactory.CreateAsync(user); var claims = principal.Claims.ToList(); if (context.Caller == IdentityServerConstants.ProfileDataCallers.UserInfoEndpoint) { claims.AddRange(UserClaimBuilder.GenerateClaimsClient(user)); } else { var roleNames = await _userManager.GetRolesAsync(user); var roles = new List <Role>(); foreach (var item in roleNames) { var role = await _roleStore.FindByNameAsync(item, default); roles.Add(role); } string?ipAddress = null; if (_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.IsIPv4MappedToIPv6) { ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); } else { ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv6().ToString(); } claims.AddRange(UserClaimBuilder.GenerateClaimsServer(user, roles, ipAddress)); } context.IssuedClaims = claims; }