excelwebzone / EWZRecaptchaBundle

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

Any way to support hCaptcha? #240

Open StudioMaX opened 4 years ago

StudioMaX commented 4 years ago

hCaptcha is a new alternative to ReCaptcha with the same API, but uses a bit different URL with the same arguments. Even Clodflare and DigitalOcean is moving to hCaptcha from ReCaptcha. Unfortunaley, there's none Symfony bundles which provides hCaptcha's support. Maybe someone has plans to implement hCaptcha in this bundle? Since it makes little sense to create a separate bundle if these two captchas are implemented almost identically.

chrisaligent commented 4 years ago

The documentation for hCaptcha seems to indicate it's pretty simple to swap over: https://docs.hcaptcha.com/switch

But there are quite a few locations in this bundle which would need to be modified/swapped based on which is used. For example: https://github.com/excelwebzone/EWZRecaptchaBundle/blob/master/src/Form/Type/EWZRecaptchaType.php#L78 Although you can change the hostname from www.google.com to www.hcaptcha.com the path is still hard-coded here, and this URL doesn't exist: https://www.hcaptcha.com/recaptcha/api.js It needs to be: https://www.hcaptcha.com/1/api.js

I guess the easiest way around this is to add a new EWZHCaptchaType Form Type which extends the EWZRecaptchaType and overrides some of these values. There's also the backend POST call, as the URL of the verification server is entirely different (even if they say the API calls themselves match): https://github.com/excelwebzone/EWZRecaptchaBundle/blob/master/src/Extension/ReCaptcha/RequestMethod/Post.php#L34

Finally I think additional Twig templates may be necessary for hCaptcha.

It's an interesting concept, it just depends if there's enough demand to justify someone spending time working on adding this feature. I'd love to do it myself but I don't have any clients using hCaptcha yet.