@@ -36,6 +36,9 @@ type reCAPTCHAV3VerifyResponse struct {
3636
3737// IsTokenValid validates a reCAPTCHA v3 token and checks if the score meets the minimum threshold.
3838func (v * GoogleReCAPTCHAV3Validator ) IsTokenValid (ctx context.Context , token string ) (bool , error ) {
39+ fmt .Printf ("[DEBUG] reCAPTCHA V3 IsTokenValid: secretKey=%s...%s, token=%s...\n " ,
40+ v .SiteSecretKey [:6 ], v .SiteSecretKey [len (v .SiteSecretKey )- 4 :], token [:min (20 , len (token ))])
41+
3942 payload := fmt .Sprintf ("secret=%s&response=%s" , v .SiteSecretKey , token )
4043
4144 req , err := http .NewRequestWithContext (ctx , http .MethodPost , v .VerifyTokenURL , strings .NewReader (payload ))
@@ -56,6 +59,8 @@ func (v *GoogleReCAPTCHAV3Validator) IsTokenValid(ctx context.Context, token str
5659 return false , fmt .Errorf ("reading body response: %w" , err )
5760 }
5861
62+ fmt .Printf ("[DEBUG] reCAPTCHA V3 Google response: %s\n " , string (respBodyBytes ))
63+
5964 var respBody reCAPTCHAV3VerifyResponse
6065 if err := json .Unmarshal (respBodyBytes , & respBody ); err != nil {
6166 return false , fmt .Errorf ("unmarshalling body response: %w" , err )
@@ -77,6 +82,7 @@ func (v *GoogleReCAPTCHAV3Validator) IsTokenValid(ctx context.Context, token str
7782 return false , fmt .Errorf ("reCAPTCHA v3 score %.2f is below minimum threshold %.2f" , respBody .Score , v .MinScore )
7883 }
7984
85+ fmt .Printf ("[DEBUG] reCAPTCHA V3 validation passed: score=%.2f, minScore=%.2f\n " , respBody .Score , v .MinScore )
8086 return true , nil
8187}
8288
0 commit comments