Ejemplo n.º 1
0
        public IActionResult CreateSecret(CreateSecretViewModel createSecretViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.View("Index", createSecretViewModel);
            }

            string  key           = this.cryptoService.CreateRandomString(24);
            string  encryptedData = this.cryptoService.EncryptData(createSecretViewModel.Secret, createSecretViewModel.Passphrase);
            var     expiry        = TimeSpan.FromSeconds(createSecretViewModel.TTL);
            Instant expiryInstant = this.clock.GetCurrentInstant().Plus(Duration.FromTimeSpan(expiry));

            var model = new RedisModel
            {
                EncryptedData = encryptedData,
                HasPassphrase = createSecretViewModel.Passphrase != null,
            };

            string redisString = JsonConvert.SerializeObject(model);

            this.redis.StringSet(key, redisString, expiry, When.Always);

            string fullAccessUrl = this.Url.Action("ShowSecret", "Secret", new { id = key }, this.Request.Scheme, this.Request.Host.Value);
            string burnUrl       = this.Url.Action("BurnSecret", "Secret", new { id = key }, this.Request.Scheme, this.Request.Host.Value);
            var    created       = new CreatedSecretViewModel
            {
                AccessUrl          = fullAccessUrl,
                BurnUrl            = burnUrl,
                PassphraseRequired = string.IsNullOrEmpty(createSecretViewModel.Passphrase),
                Expires            = expiryInstant,
                DurationString     = this.DurationString(expiry),
            };

            return(this.View(created));
        }
        public IActionResult CreateSecret(int clientId)
        {
            var model = new CreateSecretViewModel {
                ClientId = clientId
            };

            return(View(model));
        }
        public IActionResult CreateSecret(CreateSecretViewModel model)
        {
            var entity = model.ToEntity();

            var client = _configurationDbContext.Clients.Include(c => c.ClientSecrets).Single(c => c.Id == model.ClientId);

            client.ClientSecrets.Add(entity);
            _configurationDbContext.SaveChanges();

            return(RedirectToAction(nameof(Edit), new { id = model.ClientId }));
        }
Ejemplo n.º 4
0
 public static ClientSecret ToEntity(this CreateSecretViewModel model)
 {
     return(Mapper.Map <ClientSecret>(model));
 }