public async Task <IActionResult> Post([FromBody] AudienceBindingModel model) { try { if (ModelState.IsValid) { var audienceExist = await _audienceService.GetAudienceByName(model.AppName); if (audienceExist) { return(Ok(GenerateResponse(null, false, "Application name exist"))); } var audience = await _audienceService.SetupAudience(model.AppName, model.DisplayName); if (audience != null) { audience.ClientSecret = Convert.ToBase64String(Encoding.UTF8.GetBytes(audience.ClientSecret)); return(Ok(GenerateResponse(new { audience.ClientId, audience.ClientSecret, audience.AppName }, true, "Application created successfully, the details is used to access the api resources."))); } } return(Ok(GenerateResponse(ModelState, false, "All parameters is required"))); } catch (Exception ex) { _logger.LogError(ex, ex.Message); if (_env.IsDevelopment()) { return(BadRequest(ex.Message)); } else { return(BadRequest("An error occured.")); } } }