Example #1
0
        public async Task <bool> Handle(SaveClientSecretCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var client = await _clientRepository.FindByClientIdAsync(request.ClientId);

            if (client == null)
            {
                await _bus.RaiseEvent(new DomainNotification("key_not_found", $"Client named {request.ClientId} not found"));

                return(false);
            }

            var secret = new ClientSecret
            {
                Client      = client,
                Description = request.Description,
                Expiration  = request.Expiration,
                Type        = request.Type,
                Value       = request.GetHashValue()
            };
            await _clientSecretRepository.AddAsync(secret);

            if (Commit())
            {
                await _bus.RaiseEvent(new ClientSecretAddedEvent(request.ClientId, secret.Id, secret.Value, secret.Type, secret.Description));

                return(true);
            }
            return(false);
        }