Ejemplo n.º 1
0
        public async Task <string> Handle(InsertCustomClientCommand request, CancellationToken cancellationToken)
        {
            if (request.IsInvalid())
            {
                NotifyValidationErrors(request);
                return(null);
            }

            var entityToInsert = _mapper.Map <Model.CustomClient>(request);

            var clientsResult = await _customClientRepository.AllAsync(x => x.ClientId == entityToInsert.ClientId || x.ClientName == entityToInsert.ClientName);

            if (clientsResult.Any())
            {
                await _mediator.PublishBusinessNotification("Client Id already registred");

                return(null);
            }

            var clientSecret = GenerateSecret();

            entityToInsert.ClientSecrets = new List <Secret> {
                new Secret(clientSecret.Sha256())
            };

            var entityInserted = await _customClientRepository.AddAsync(entityToInsert);

            return(clientSecret);
        }
        public async Task <bool> IsOriginAllowedAsync(string origin)
        {
            var result = await _customClientRepository.AllAsync(x => x.Enabled && x.AllowedCorsOrigins != null && x.AllowedCorsOrigins.Contains(origin));

            _logger.LogDebug($"Origin {origin} is allowed: {result.Any()}");

            return(result.Any());
        }