public void AddClientSecret(ClientSecretDto clientPropertyDto) { ClientSecret clientProperty = clientPropertyDto.ToEntity(); this.Session.Save(clientProperty); this.Session.Flush(); }
public async Task <IActionResult> AddApiSecret(ClientSecretDto apiSecret) { if (!ModelState.IsValid) { return(BadRequest(ModelStateErrors)); } var result = await _clientAppService.AddClientSecretAsync(apiSecret); return(ResultResponse(result, "添加ApiSecret成功")); }
public async Task CreateClientSecret(int id, string type, string description, string value) { string hash = value.Sha256(); DateTime?expired = DateTime.Now.AddMonths(1); var req = new ClientSecretDto(type, description, hash, expired); var result = await apiKYC.CreateClientSecret(id, req); Assert.True(result); }
public void UpdateClientSecret(int id, ClientSecretDto clientSecretDto) { ClientSecret clientSecret = this.Session.Get <ClientSecret>(id); if (clientSecret == null) { throw new FluentValidationException($"客户端属性{id}不存在。"); } clientSecret = clientSecretDto.ToEntity(clientSecret); this.Session.Save(clientSecret); this.Session.Flush(); }
public async Task <bool> AddSecretToClient(int clientId, ClientSecretDto secret) { await this._configContext.AddAsync(new IdentityServer4.EntityFramework.Entities.ClientSecret { ClientId = secret.ClientId, Description = secret.Description, Value = secret.Value.Sha256(), Expiration = secret.Expiration, Type = secret.Type, Created = secret.Created }); return(true); }
private void HashClientSharedSecret(ClientSecretDto clientSecret) { if (clientSecret.Type != SharedSecret) { return; } if (clientSecret.HashType == HashType.Sha256) { clientSecret.Value = clientSecret.Value.Sha256(); } else if (clientSecret.HashType == HashType.Sha512) { clientSecret.Value = clientSecret.Value.Sha512(); } }
public async Task RemoveSecretFromClaims(ClientSecretDto secret) { var client = await this._configContext .Clients.Include(c => c.ClientSecrets) .FirstOrDefaultAsync(i => i.Id == secret.ClientId); if (client == null) { throw new Exception("Entity Not Found"); } var foundSecret = client.ClientSecrets.FirstOrDefault(c => c.Id == secret.Id); if (foundSecret == null) { throw new Exception("Secret not found"); } this._configContext.Remove(foundSecret); }
public async Task <ActionResult> AddSecretToClient(int clientId, [FromBody] ClientSecretDto secret) { if (clientId == 0 || secret == null) { return(BadRequest()); } var currentClient = await this._configurationManagementService.ReturnClientAsync(clientId); if (currentClient == null) { return(NotFound()); } var result = await this._configurationManagementService.AddSecretToClient(clientId, secret); await this._configurationManagementService.SaveChangesAsync(); return(Ok(result)); }
public async Task <bool> AddClientSecretAsync(ClientSecretDto clientSecret) { var client = await _clientRepository.GetAll().Where(x => x.Id == clientSecret.ClientId).SingleOrDefaultAsync(); var secret = _mapper.Map <ClientSecret>(clientSecret); if (clientSecret.Hash == HashType.Sha256) { secret.Value = clientSecret.Value.Sha256(); } else if (clientSecret.Hash == HashType.Sha512) { secret.Value = clientSecret.Value.Sha512(); } secret.Client = client; await _clientSecretRepository.AddAsync(secret); return(await _clientSecretRepository.SaveChangesAsync() > 0); }
public async Task <bool> CreateClientSecret(int?id, ClientSecretDto secret) { // discover endpoints from metadata var client = new HttpClient(); var disco = await client.GetDiscoveryDocumentAsync(IdentityEndpoint.Discovery); if (disco.IsError) { return(false); } // request token var req = new PasswordTokenRequest { Address = disco.TokenEndpoint, ClientId = IdentityEndpoint.ClientID, ClientSecret = IdentityEndpoint.Secret, Scope = IdentityEndpoint.Scopes, UserName = IdentityEndpoint.UserName, Password = IdentityEndpoint.Password }; var tokenResponse = await client.RequestPasswordTokenAsync(req); if (tokenResponse.IsError) { return(false); } var apiClient = new HttpClient(); apiClient.SetBearerToken(tokenResponse.AccessToken); var dataJson = JsonSerializer.Serialize(secret); var stringContent = new StringContent(dataJson, Encoding.UTF8, "application/json"); var response = await apiClient.PostAsync(IdentityEndpoint.ClientUri + $"/{id.Value}/Secrets", stringContent); return(response.IsSuccessStatusCode); }
public static ClientSecret ToEntity(this ClientSecretDto clientSecretDto, ClientSecret clientSecret = null) { return(Mapper.Map <ClientSecretDto, ClientSecret>(clientSecretDto, clientSecret)); }