Exemple #1
0
        private async Task <TokenRequestValidationResult> RunValidationAsync(Func <NameValueCollection, Task <TokenRequestValidationResult> > validationFunc, NameValueCollection parameters)
        {
            // run standard validation
            var result = await validationFunc(parameters);

            if (result.IsError)
            {
                return(result);
            }

            // run custom validation
            _logger.LogTrace("Calling into custom request validator: {type}", _customRequestValidator.GetType().FullName);

            var customValidationContext = new CustomTokenRequestValidationContext {
                Result = result
            };
            await _customRequestValidator.ValidateAsync(customValidationContext);

            if (customValidationContext.Result.IsError)
            {
                if (customValidationContext.Result.Error.IsPresent())
                {
                    LogError("Custom token request validator", new { error = customValidationContext.Result.Error });
                }
                else
                {
                    LogError("Custom token request validator error");
                }

                return(customValidationContext.Result);
            }

            LogSuccess();
            return(customValidationContext.Result);
        }
 /// <summary>
 /// Custom validation logic for a token request.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns>
 /// The validation result
 /// </returns>
 public Task ValidateAsync(CustomTokenRequestValidationContext context)
 {
     return(Task.CompletedTask);
 }