public async Task <ClientSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

            var parsedSecret = await _parser.ParseAsync(_environment.Environment);

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

                Logger.Info("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.Info("No client with that id found. aborting");
                return(fail);
            }

            if (!client.RequireClientSecret)
            {
                Logger.Debug("Public Client - skipping secret validation success");
            }
            else
            {
                var result = await _validator.ValidateAsync(parsedSecret, client.ClientSecrets);

                if (result.Success == false)
                {
                    await RaiseFailureEvent(client.ClientId, "Invalid client secret");

                    Logger.Info("Client validation failed.");

                    return(fail);
                }
            }

            Logger.Info("Client validation success");

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

            await RaiseSuccessEvent(client.ClientId);

            return(success);
        }
        public async Task<ClientSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

            // see if a registered parser finds a secret on the request
            ParsedSecret parsedSecret = null;
            foreach (var parser in _parsers)
            {
                parsedSecret = await parser.ParseAsync(_environment.Environment);
                if (parsedSecret != null)
                {
                    Logger.DebugFormat("Parser found client secret: {0}", parser.GetType().Name);
                    Logger.InfoFormat("Client secret id found: {0}", parsedSecret.Id);

                    break;
                }
            }

            if (parsedSecret == null)
            {
                Logger.Info("No client secret found");
                return fail;
            }

            // load client
            var client = await _clients.FindClientByIdAsync(parsedSecret.Id);
            if (client == null)
            {
                Logger.Info("No client with that id found. aborting");
                return fail;
            }

            // see if a registered validator can validate the secret
            foreach (var validator in _validators)
            {
                var secretValidationResult = await validator.ValidateAsync(client.ClientSecrets, parsedSecret);

                if (secretValidationResult.Success)
                {
                    Logger.DebugFormat("Secret validator success: {0}", validator.GetType().Name);
                    Logger.Info("Client validation success");

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

                    return success;
                }
            }

            Logger.Info("Client validation failed.");
            return fail;
        }
        public async Task<ClientSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

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

                Logger.Info("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.Info("No client with that id found. aborting");
                return fail;
            }

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

            if (result.Success)
            {
                Logger.Info("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.Info("Client validation failed.");
            
            return fail;
        }
        public async Task <ClientSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start client validation");

            var fail = new ClientSecretValidationResult
            {
                IsError = true
            };

            // see if a registered parser finds a secret on the request
            ParsedSecret parsedSecret = null;

            foreach (var parser in _parsers)
            {
                parsedSecret = await parser.ParseAsync(_environment.Environment);

                if (parsedSecret != null)
                {
                    Logger.DebugFormat("Parser found client secret: {0}", parser.GetType().Name);
                    Logger.InfoFormat("Client secret id found: {0}", parsedSecret.Id);

                    break;
                }
            }

            if (parsedSecret == null)
            {
                Logger.Info("No client secret found");
                return(fail);
            }

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

            if (client == null)
            {
                Logger.Info("No client with that id found. aborting");
                return(fail);
            }

            // see if a registered validator can validate the secret
            foreach (var validator in _validators)
            {
                var secretValidationResult = await validator.ValidateAsync(client.ClientSecrets, parsedSecret);

                if (secretValidationResult.Success)
                {
                    Logger.DebugFormat("Secret validator success: {0}", validator.GetType().Name);
                    Logger.Info("Client validation success");

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

                    return(success);
                }
            }

            Logger.Info("Client validation failed.");
            return(fail);
        }