public async Task <UpdateClientOutput> UpdateClient(UpdateClientInput input) { var client = input.MapTo <Client>(); var clientUpdated = await _clientManager.Update(client); return(clientUpdated.MapTo <UpdateClientOutput>()); }
public async Task <Client> UpdateClient([Service] ApplicationDbContext db, UpdateClientInput input) { var client = await db.FindAsync <Client>(input.Id); client.ClientId = input.ClientId; client.ClientName = input.ClientName; foreach (var clientSecretInput in input.ClientSecrets) { var clientSecretEntity = await db.FindAsync <ClientSecret>(clientSecretInput.Id) ?? new ClientSecret { Created = DateTime.Now, ClientId = client.Id }; clientSecretEntity.Description = clientSecretInput.Description; clientSecretEntity.Expiration = clientSecretInput.Expiration; clientSecretEntity.Type = clientSecretInput.Type; clientSecretEntity.Value = clientSecretInput.Value; if (clientSecretEntity.Id == 0) { db.ClientSecrets.Add(clientSecretEntity); } } var clientSecretIdsInInput = input.ClientSecrets.Select(cs => cs.Id).ToArray(); var clientSecretEntitiesToDelete = db.ClientSecrets.Where(cs => cs.ClientId == client.Id && !clientSecretIdsInInput.Contains(cs.Id)).ToList(); db.ClientSecrets.RemoveRange(clientSecretEntitiesToDelete); await db.SaveChangesAsync(); return(client); }
public async Task <UpdateClientOutput> UpdateClient(UpdateClientInput input) { if (!Regular.IsMatchLettersNumbers(input.ClientId)) { return(new UpdateClientOutput() { ErrorMessage = "客户端Id只能输入数字和字母" }); } if (!string.IsNullOrEmpty(input.ClientSecret) && !Regular.IsMatchLettersNumbers(input.ClientSecret)) { return(new UpdateClientOutput() { ErrorMessage = "密匙只能输入数字和字母" }); } if (!string.IsNullOrEmpty(input.ClientSecret) && (input.ClientSecret.Length < 6 || input.ClientSecret.Length > 50)) { return(new UpdateClientOutput() { ErrorMessage = "客户端密匙长度必须大于或等于6,小于或等于50" }); } Expression <Func <Client, object> >[] clientLoad = new Expression <Func <Client, object> >[] { e => e.AllowedGrantTypes, e => e.RedirectUris, e => e.PostLogoutRedirectUris, e => e.AllowedScopes, }; var client = _clientManager.GetClientInclude(input.Id, clientLoad); _clientManager.UpdateAllowedGrantType(client, input.AllowedGrantType); _clientManager.UpdateAllowedScopes(client, input.AllowedScopes); _clientManager.UpdatePostLogoutRedirectUris(client, input.PostLogoutRedirectUris); _clientManager.UpdateRedirectUris(client, input.RedirectUris); // 如果密匙不为空,则更新 if (!string.IsNullOrEmpty(input.ClientSecret)) { _clientManager.UpdateSecrets(client, new List <string>() { input.ClientSecret }); } client.ClientId = input.ClientId; client.ClientName = input.ClientName; client.AllowAccessTokensViaBrowser = input.AllowAccessTokensViaBrowser; client.AllowOfflineAccess = input.AllowOfflineAccess; client.Enabled = input.Enabled; client.AccessTokenType = (int)("jwt".Equals(input.AccessTokenType, StringComparison.OrdinalIgnoreCase) ? IdentityServer4.Models.AccessTokenType.Jwt : IdentityServer4.Models.AccessTokenType.Reference); return(new UpdateClientOutput()); }
public async Task Update(UpdateClientInput input) { Logger.Info("Updating a task for input: " + input); var existingClient = await _clientRepository.FirstOrDefaultAsync(input.ClientId); if (existingClient == null) { throw new UserFriendlyException(L("CouldNotFindTheTaskMessage")); } var updatingClient = ObjectMapper.Map <Client>(input); await _clientRepository.UpdateAsync(updatingClient); }