excelwebzone / EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field for Symfony.
MIT License
396 stars 160 forks source link

ReCaptcha Version 3 #218

Open seddighi78 opened 5 years ago

seddighi78 commented 5 years ago

Is possible to use the ReCaptcha version 3 and if yes how to use it?

chrisaligent commented 5 years ago

The server-side code for verifying the CAPTCHA (as well as the frontend api.js JS URL) seems to be the same on v2 and v3, so it's just the front-end implementation which would need to be modified. We've decided to stick with v2 for now, but v3 didn't look too difficult to add: https://developers.google.com/recaptcha/docs/v3#integration

This PHP code from this package's README shows how to manually implement v2 frontend code:

<div id="recaptcha-container"></div>
<script type="text/javascript">
    $(document).ready(function() {
        $.getScript("<?php echo \EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType::RECAPTCHA_API_JS_SERVER ?>", function() {
            Recaptcha.create("<?php echo $form['recaptcha']->get('public_key') ?>", "recaptcha-container", {
                theme: "clean",
            });
        });
    };
</script>

I'm guessing v3 would be something like this:

<script src="<?php echo \EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType::RECAPTCHA_API_JS_SERVER ?>?render=<?php echo $form['recaptcha']->get('public_key') ?>"></script>
  <script>
  grecaptcha.ready(function() {
      grecaptcha.execute('<?php echo $form['recaptcha']->get('public_key') ?>', {action: 'homepage'}).then(function(token) {
         ...
      });
  });
  </script>

NOTE: The above code is entirely untested but might be enough to get you started :slightly_smiling_face:

alexander-schranz commented 5 years ago

maybe adding a additional configuration with version could be added:

ewz_recaptcha:
    version: 'v3' # defaults to v2

so the backward compatibility is given?

MichaelBrauner commented 5 years ago

So... is it possible to simply do:

ewz_recaptcha:
    version: 'v3' # defaults to v2
man-andy commented 5 years ago

any updates regarding this?

spavanes commented 5 years ago

I'm also interested in this feature.

prugala commented 5 years ago

I made simple bundle for reCAPTHCA v3 if someone want to use https://github.com/prugala/PRRecaptchaBundle

@spavanes @man-andy

Astro-Otter-Space commented 5 years ago

I made simple bundle for reCAPTHCA v3 if someone want to use https://github.com/prugala/PRRecaptchaBundle

@spavanes @man-andy

I'm intersting but i need to use it on an old symfony version (2.7). Is it compatible ?

itinance commented 4 years ago

I've tried suggestion from @alexander-schranz

ewz_recaptcha:
    version: 'v3' # defaults to v2

But this option does not exists in current version 1.5:

Unrecognized option "version" under "ewz_recaptcha".

Any ideas?

prugala commented 4 years ago

@itinance it was idea only. As I wrote above I made simple bundle for Recaptcha V3: https://github.com/prugala/PRRecaptchaBundle

alexander-schranz commented 3 years ago

This seems to be implemented in #256 Thx to @manuxi