@@ -39,7 +39,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
3939
4040 ValidationResponse validationResponse ;
4141
42- if ( ! TryGetRecaptchaToken ( context . HttpContext . Request , out string ? token ) )
42+ if ( ! ValidateRecaptchaFilter . TryGetRecaptchaToken ( context . HttpContext . Request , out string ? token ) )
4343 {
4444 _logger . LogWarning ( Resources . RecaptchaResponseTokenMissing ) ;
4545
@@ -57,7 +57,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
5757 validationResponse = await _recaptchaService . ValidateRecaptchaResponse ( token , GetRemoteIp ( context ) ) . ConfigureAwait ( true ) ;
5858 }
5959
60- TryAddResponseToActionAguments ( context , validationResponse ) ;
60+ ValidateRecaptchaFilter . TryAddResponseToActionAguments ( context , validationResponse ) ;
6161
6262 if ( ! ShouldShortCircuit ( context , validationResponse ) )
6363 {
@@ -71,19 +71,34 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
7171 context . HttpContext . Connection . RemoteIpAddress . ToString ( ) :
7272 null ;
7373 }
74- private bool TryGetRecaptchaToken ( HttpRequest request , [ NotNullWhen ( true ) ] out string ? token )
74+ private bool ShouldShortCircuit ( ActionExecutingContext context , ValidationResponse response )
75+ {
76+ if ( ! response . Success )
77+ {
78+ _logger . LogInformation ( Resources . InvalidResponseTokenMessage ) ;
79+
80+ if ( OnValidationFailedAction == ValidationFailedAction . BlockRequest )
81+ {
82+ context . Result = new RecaptchaValidationFailedResult ( ) ;
83+ return true ;
84+ }
85+ }
86+
87+ return false ;
88+ }
89+ private static bool TryGetRecaptchaToken ( HttpRequest request , [ NotNullWhen ( true ) ] out string ? token )
7590 {
7691 if ( request . Headers . ContainsKey ( RecaptchaServiceConstants . TokenKeyName ) )
7792 {
7893 token = request . Headers [ RecaptchaServiceConstants . TokenKeyName ] ;
7994 }
80- else if ( request . HasFormContentType && request . Form . ContainsKey ( RecaptchaServiceConstants . TokenKeyName . ToLowerInvariant ( ) ) )
95+ else if ( request . HasFormContentType && request . Form . ContainsKey ( RecaptchaServiceConstants . TokenKeyNameLower ) )
8196 {
82- token = request . Form [ RecaptchaServiceConstants . TokenKeyName . ToLowerInvariant ( ) ] ;
97+ token = request . Form [ RecaptchaServiceConstants . TokenKeyNameLower ] ;
8398 }
84- else if ( request . Query . ContainsKey ( RecaptchaServiceConstants . TokenKeyName . ToLowerInvariant ( ) ) )
99+ else if ( request . Query . ContainsKey ( RecaptchaServiceConstants . TokenKeyNameLower ) )
85100 {
86- token = request . Query [ RecaptchaServiceConstants . TokenKeyName . ToLowerInvariant ( ) ] ;
101+ token = request . Query [ RecaptchaServiceConstants . TokenKeyNameLower ] ;
87102 }
88103 else
89104 {
@@ -92,22 +107,7 @@ private bool TryGetRecaptchaToken(HttpRequest request, [NotNullWhen(true)] out s
92107
93108 return token != null ;
94109 }
95- private bool ShouldShortCircuit ( ActionExecutingContext context , ValidationResponse response )
96- {
97- if ( ! response . Success )
98- {
99- _logger . LogInformation ( Resources . InvalidResponseTokenMessage ) ;
100-
101- if ( OnValidationFailedAction == ValidationFailedAction . BlockRequest )
102- {
103- context . Result = new RecaptchaValidationFailedResult ( ) ;
104- return true ;
105- }
106- }
107-
108- return false ;
109- }
110- private void TryAddResponseToActionAguments ( ActionExecutingContext context , ValidationResponse response )
110+ private static void TryAddResponseToActionAguments ( ActionExecutingContext context , ValidationResponse response )
111111 {
112112 if ( context . ActionArguments . Any ( pair => pair . Value is ValidationResponse ) )
113113 {
0 commit comments