protected virtual async Task UpdateApiResourceByInputAsync(IdentityResource identityResource, IdentityResourceCreateOrUpdateDto input) { if (!string.Equals(identityResource.Name, input.Name, StringComparison.InvariantCultureIgnoreCase)) { identityResource.Name = input.Name; } if (!string.Equals(identityResource.Description, input.Description, StringComparison.InvariantCultureIgnoreCase)) { identityResource.Description = input.Description; } if (!string.Equals(identityResource.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase)) { identityResource.DisplayName = input.DisplayName; } identityResource.Emphasize = input.Emphasize; identityResource.Enabled = input.Enabled; identityResource.Required = input.Required; identityResource.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument; if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageClaims)) { // 删除不存在的UserClaim identityResource.UserClaims.RemoveAll(claim => input.UserClaims.Any(inputClaim => claim.Type == inputClaim.Type)); foreach (var inputClaim in input.UserClaims) { var userClaim = identityResource.FindUserClaim(inputClaim.Type); if (userClaim == null) { identityResource.AddUserClaim(inputClaim.Type); } } } if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageProperties)) { // 删除不存在的Property identityResource.Properties.RemoveAll(prop => !input.Properties.Any(inputProp => prop.Key == inputProp.Key)); foreach (var inputProp in input.Properties) { var identityResourceProperty = identityResource.FindProperty(inputProp.Key); if (identityResourceProperty == null) { identityResource.AddProperty(inputProp.Key, inputProp.Value); } else { identityResourceProperty.Value = inputProp.Value; } } } }