public ActionResult Index()
        {
            if (ConfigurationRepository.Keys.SigningCertificate != null)
            {
                return RedirectToAction("index", "home");
            }

            var model = new InitialConfigurationModel
            {
                AvailableCertificates = GetAvailableCertificatesFromStore(),
                IssuerUri = ConfigurationRepository.Global.IssuerUri,
                SiteName = ConfigurationRepository.Global.SiteName
            };

            return View(model);
        }
        public ActionResult Index(InitialConfigurationModel model)
        {
            if (ConfigurationRepository.Keys.SigningCertificate != null)
            {
                return RedirectToAction("index", "home");
            }

            if (ModelState.IsValid)
            {
                var config = ConfigurationRepository.Global;
                config.SiteName = model.SiteName;
                config.IssuerUri = model.IssuerUri;

                // create default IdentityServer groups and admin user.
                if (model.CreateDefaultAccounts)
                {
                    var errors = CreateDefaultAccounts(model.UserName, model.Password);

                    if (errors.Count != 0)
                    {
                        errors.ForEach(e => ModelState.AddModelError("", e));
                        model.AvailableCertificates = GetAvailableCertificatesFromStore();
                        return View(model);
                    }
                }

                // update global config
                ConfigurationRepository.Global = config;

                var keys = ConfigurationRepository.Keys;
                try
                {
                    var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(model.SigningCertificate, false).First();

                    // make sure we can access the private key
                    var pk = cert.PrivateKey;

                    keys.SigningCertificate = cert;
                }
                catch (CryptographicException)
                {
                    ModelState.AddModelError("", string.Format(Resources.InitialConfigurationController.NoReadAccessPrivateKey, WindowsIdentity.GetCurrent().Name));
                    model.AvailableCertificates = GetAvailableCertificatesFromStore();
                    return View(model);
                }

                if (string.IsNullOrWhiteSpace(keys.SymmetricSigningKey))
                {
                    keys.SymmetricSigningKey = Convert.ToBase64String(CryptoRandom.CreateRandomKey(32));
                }

                // updates key material config
                ConfigurationRepository.Keys = keys;

                return RedirectToAction("index", "home");
            }

            ModelState.AddModelError("", Resources.InitialConfigurationController.ErrorsOcurred);
            model.AvailableCertificates = GetAvailableCertificatesFromStore();
            return View(model);
        }