示例#1
0
        public async Task <ClientSecretValidationResult> ValidateAsync(HttpContext context)
        {
            _logger.LogTrace("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

            var parsedSecret = await _parser.ParseAsync(context);

            if (parsedSecret == null)
            {
                await RaiseFailureEvent("unknown", "No client id or secret found");

                _logger.LogInformation("No client secret found");
                return(fail);
            }

            // load client
            var client = await _clients.FindClientByIdAsync(parsedSecret.Id);

            if (client == null)
            {
                await RaiseFailureEvent(parsedSecret.Id, "Unknown client");

                _logger.LogInformation("No client with that id found. aborting");
                return(fail);
            }

            var result = await _validator.ValidateAsync(parsedSecret, client.ClientSecrets);

            if (result.Success)
            {
                _logger.LogInformation("Client validation success");

                var success = new ClientSecretValidationResult
                {
                    IsError = false,
                    Client  = client
                };

                await RaiseSuccessEvent(client.ClientId);

                return(success);
            }

            await RaiseFailureEvent(client.ClientId, "Invalid client secret");

            _logger.LogWarning("Client validation failed client {clientId}.", client.ClientId);

            return(fail);
        }
        public async Task<ClientSecretValidationResult> ValidateAsync(HttpContext context)
        {
            _logger.LogVerbose("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

            var parsedSecret = await _parser.ParseAsync(context);
            if (parsedSecret == null)
            {
                await RaiseFailureEvent("unknown", "No client id or secret found");

                _logger.LogInformation("No client secret found");
                return fail;
            }

            // load client
            var client = await _clients.FindClientByIdAsync(parsedSecret.Id);
            if (client == null)
            {
                await RaiseFailureEvent(parsedSecret.Id, "Unknown client");

                _logger.LogInformation("No client with that id found. aborting");
                return fail;
            }

            var result = await _validator.ValidateAsync(parsedSecret, client.ClientSecrets);

            if (result.Success)
            {
                _logger.LogInformation("Client validation success");

                var success = new ClientSecretValidationResult
                {
                    IsError = false,
                    Client = client
                };

                await RaiseSuccessEvent(client.ClientId);
                return success;
            }

            await RaiseFailureEvent(client.ClientId, "Invalid client secret");
            _logger.LogWarning("Client validation failed client {clientId}.", client.ClientId);

            return fail;
        }