karser / KarserRecaptcha3Bundle

Google ReCAPTCHA v3 for Symfony
MIT License
160 stars 22 forks source link

Violation "Could not connect to service" #41

Closed LyamD closed 3 years ago

LyamD commented 3 years ago

Hi,

I'm having an issue with the validator, it keep raising a violation "Could not connect to service" I've followed the troubleshooting checklist. I've had and resolved issues with the site key & domains. Setting the SCP didn't change anything. If a put the score threshold too high, the validator return a violation 'score too low', making me think that I am in fact getting a response from google.

How can I at least get more information from this error ?

Thanks.

karser commented 3 years ago

Hi, have you tried adding {{ errorCodes }}? https://github.com/karser/KarserRecaptcha3Bundle#how-to-show-errors-from-the-captchas-response

LyamD commented 3 years ago

Yes, I should have been more clear sorry. It's actually the {{ errorCodes }} that's returning me 'Could not connect to service'

karser commented 3 years ago

Looks like in case of a bad response, google/recaptcha just throws the standard error constant without letting us know the actual error

return '{"success": false, "error-codes": ["'.ReCaptcha::E_CONNECTION_FAILED.'"]}';

You can temporarily modify google/recaptcha/src/ReCaptcha/RequestMethod/Post.php in the vendor folder to get the actual error from Google Recaptcha https://stackoverflow.com/questions/15620124/http-requests-with-file-get-contents-getting-the-response-code

$response = file_get_contents("http://example.com", false, stream_context_create(['http' => ['ignore_errors' => true]]));
var_dump($response);
var_dump($http_response_header);
LyamD commented 3 years ago

It appears that submit() in .../RequestMethod/Post.php is never called, instead it's always passing through .../RequestMethod/CurlPost.php.

I've dumped $response & $options (in CurlPost.php) image

But I don't really know what to think of this. I still don't understand how it can get the error "Score threshold not met" if there is no response (I'm forcing it by changing the score_threshold at 1 in karser_recaptcha3.yaml)

karser commented 3 years ago

Sorry for the wrong information. Try to get the error from curl then

        $response = $this->curl->exec($handle);
        $body = curl_error($handle);
        $http_status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
        $curl_errno= curl_errno($handle);
        var_dump($body, $http_status, $curl_errno);
        $this->curl->close($handle);
LyamD commented 3 years ago

Thanks ! The error seems to be about SSL Certificate: "Unable to get local issuer certificate", probably due to the fact that i'm in localhost. I'm gonna try various things in the next days (became busy with something else in-between ). I'll keep this post updated (I hope with the solution when I found one)

karser commented 3 years ago

It probably has to do with your local setup. Take a look at this article and video https://ourcodeworld.com/articles/read/196/xampp-wampp-php-ssl-certificate-error-unable-to-get-local-issuer-certificate

LyamD commented 3 years ago

Thanks, I tried to fix local setup but didn't manage to, but as soon as I pushed it to my dev server (with an already valid SSL Cert) it worked instant. Closing the issue

AbdullahAlhariri commented 1 year ago

I'm also got this issue. But my my localhost is ssl encrypted. on symfony 6.2 it does work, but when I switch to 5.3 it doesn't. Does this sound familiar?