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

            var fail = new ScopeSecretValidationResult
            {
                IsError = true
            };

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

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

                Logger.Info("No scope secret found");
                return(fail);
            }

            // load scope
            var scope = (await _scopes.FindScopesAsync(new[] { parsedSecret.Id })).FirstOrDefault();

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

                Logger.Info("No scope with that name found. aborting");
                return(fail);
            }

            var result = await _validator.ValidateAsync(parsedSecret, scope.ScopeSecrets);

            if (result.Success)
            {
                Logger.Info("Scope validation success");

                var success = new ScopeSecretValidationResult
                {
                    IsError = false,
                    Scope   = scope
                };

                await RaiseSuccessEvent(scope.Name);

                return(success);
            }

            await RaiseFailureEvent(scope.Name, "Invalid client secret");

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

            return(fail);
        }
        public async Task<ScopeSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start scope validation");

            var fail = new ScopeSecretValidationResult
            {
                IsError = true
            };

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

                Logger.Info("No scope secret found");
                return fail;
            }

            // load scope
            var scope = (await _scopes.FindScopesAsync(new[] { parsedSecret.Id })).FirstOrDefault();
            if (scope == null)
            {
                await RaiseFailureEvent(parsedSecret.Id, "Unknown scope");

                Logger.Info("No scope with that name found. aborting");
                return fail;
            }

            var result = await _validator.ValidateAsync(parsedSecret, scope.ScopeSecrets);
            if (result.Success)
            {
                Logger.Info("Scope validation success");

                var success = new ScopeSecretValidationResult
                {
                    IsError = false,
                    Scope = scope
                };

                await RaiseSuccessEvent(scope.Name);
                return success;
            }

            await RaiseFailureEvent(scope.Name, "Invalid client secret");
            Logger.Info("Scope validation failed.");

            return fail;
        }
        public async Task <ScopeSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start scope validation");

            var fail = new ScopeSecretValidationResult
            {
                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 scope secret: {0}", parser.GetType().Name);
                    Logger.InfoFormat("Scope name found: {0}", parsedSecret.Id);

                    break;
                }
            }

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

                Logger.Info("No scope secret found");
                return(fail);
            }

            // load scope
            var scope = (await _scopes.FindScopesAsync(new[] { parsedSecret.Id })).FirstOrDefault();

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

                Logger.Info("No scope with that name found. aborting");
                return(fail);
            }

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

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

                    var success = new ScopeSecretValidationResult
                    {
                        IsError = false,
                        Scope   = scope
                    };

                    await RaiseSuccessEvent(scope.Name);

                    return(success);
                }
            }

            await RaiseFailureEvent(scope.Name, "Invalid client secret");

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

            return(fail);
        }
        public async Task<ScopeSecretValidationResult> ValidateAsync()
        {
            Logger.Debug("Start scope validation");

            var fail = new ScopeSecretValidationResult
            {
                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 scope secret: {0}", parser.GetType().Name);
                    Logger.InfoFormat("Scope name found: {0}", parsedSecret.Id);

                    break;
                }
            }

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

                Logger.Info("No scope secret found");
                return fail;
            }

            // load scope
            var scope = (await _scopes.FindScopesAsync(new[] { parsedSecret.Id })).FirstOrDefault();
            if (scope == null)
            {
                await RaiseFailureEvent(parsedSecret.Id, "Unknown client");

                Logger.Info("No scope with that name found. aborting");
                return fail;
            }

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

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

                    var success = new ScopeSecretValidationResult
                    {
                        IsError = false,
                        Scope = scope
                    };

                    await RaiseSuccessEvent(scope.Name);
                    return success;
                }
            }

            await RaiseFailureEvent(scope.Name, "Invalid client secret");
            Logger.Info("Scope validation failed.");

            return fail;
        }