//[ValidateAntiForgeryToken]
        public async Task <IActionResult> Save(TeamCityConfigurationViewModel teamCityConfigurationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            if (await _tenantService.ValidateTokenAsync(teamCityConfigurationViewModel.JwtToken))
            {
                var serverBuildConfiguration = new ServerBuildConfiguration
                {
                    ServerRootUrl = teamCityConfigurationViewModel.ServerUrl,
                };

                serverBuildConfiguration.BuildConfiguration.MaxWaitDurationInMinutes = teamCityConfigurationViewModel.MaxWaitDurationInMinutes;
                serverBuildConfiguration.BuildConfiguration.BuildConfigurationIds    = teamCityConfigurationViewModel.BuildConfigurationIds;

                await _tenantService.SetConfigurationAsync(teamCityConfigurationViewModel.JwtToken, serverBuildConfiguration);

                await _teamCityAggregator.ReInitializeFromConfigurationAsync();

                return(View("Index", teamCityConfigurationViewModel));
            }

            return(RedirectToAction("Index"));
        }
        // GET:
        public async Task <IActionResult> Index([FromQuery(Name = "signed_request")] string signedRequest)
        {
            if (await _tenantService.ValidateTokenAsync(signedRequest))
            {
                var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
                var readToken = jwtSecurityTokenHandler.ReadToken(signedRequest);

                var teamCityConfigurationViewModel = new TeamCityConfigurationViewModel();

                var serverBuildConfiguration = await _tenantService.GetConfigurationAsync <ServerBuildConfiguration>(readToken.Issuer);

                teamCityConfigurationViewModel.ServerUrl                = serverBuildConfiguration.ServerRootUrl;
                teamCityConfigurationViewModel.BuildConfigurationIds    = serverBuildConfiguration.BuildConfiguration.BuildConfigurationIds;
                teamCityConfigurationViewModel.MaxWaitDurationInMinutes = serverBuildConfiguration.BuildConfiguration.MaxWaitDurationInMinutes;

                return(View(teamCityConfigurationViewModel));
            }

            return(BadRequest());
        }