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

            var savedClient = await _clientRepository.GetByClientId(request.ClientId);

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));

                return;
            }

            var secret = new ClientSecret
            {
                Client      = savedClient,
                Description = request.Description,
                Expiration  = request.Expiration,
                Type        = request.Type,
                Value       = request.GetValue()
            };

            _clientSecretRepository.Add(secret);

            if (Commit())
            {
                await Bus.RaiseEvent(new NewClientSecretEvent(request.Id, request.ClientId, secret.Type, secret.Description));
            }
        }
Example #2
0
        public async Task <bool> Handle(SaveClientSecretCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _clientRepository.GetByClientId(request.ClientId);

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));

                return(false);
            }

            var secret = request.ToEntity(savedClient);

            _clientSecretRepository.Add(secret);

            if (await Commit())
            {
                await Bus.RaiseEvent(new NewClientSecretEvent(request.Id, request.ClientId, secret.Type, secret.Description));

                return(true);
            }
            return(false);
        }
Example #3
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);
        }