public object SaveClientApp(ClientAppModel model) { var client = clientAppService.GetClientApp(model.Code); if (client != null) { throw new ArgumentException("client app has been exists!"); } client = clientAppService.GetClientAppByName(model.Title); if (client != null) { throw new ArgumentException("client app title has been exists!"); } client = new ClientApp(model.Code, model.Title, model.Description); clientAppService.CreateClientApp(client); return(new { Code = client.Code, Title = client.Title, Desc = client.Description, Secret = client.SecretCode }); }
public async Task <IActionResult> Post([FromBody] ClientAppModel client) { IActionResult response = Unauthorized(); try { if (ModelState.IsValid) { var app = new AppAudiences(); app.Id = Guid.NewGuid(); //app.AppSecretKey = GetRandomCharacter(16, RemoveCharacter(app.Id.ToString("N"))); var key = Encoding.UTF8.GetBytes(client.Password); var message = Encoding.UTF8.GetBytes(app.Id.ToString("N")); app.AppSecretKey = ReplaceInvalidCharacterForJwt(Convert.ToBase64String(HashingByHMACSHA256(message, key))); app.CreatedDateTime = DateTime.UtcNow; app.ExpiryDate = DateTime.UtcNow.AddMonths(3); app.CreatedBy = client.CreatedBy; app.Name = client.Name; app.ContactEmail = client.ContactEmail; var fb = new Firebase(_config); var resp = await fb.PutAppAudiences(app); var jsonString = resp.Content.ReadAsStringAsync().Result.ToString(); if (resp.StatusCode == HttpStatusCode.OK) { response = Ok(app); return(response); } else { return(response); } } else { response = BadRequest(); return(response); } } catch (Exception ex) { response = BadRequest(ex.Message); return(response); } }