react-google-recaptcha icon indicating copy to clipboard operation
react-google-recaptcha copied to clipboard

Google Recaptcha Enterprise

Open Beta6484 opened this issue 4 years ago • 6 comments

react-google-recaptcha version: 2.1.0

Hello, is there any way to use this plugin with recaptcha enterprise? Currently I've configured the enterprise key, no error appears but in the recaptcha graphics I get hits marked "without captcha".

Beta6484 avatar Oct 05 '21 19:10 Beta6484

i have checked the code and seems like it doesn't fetch the enterprise js which is https://www.google.com/recaptcha/enterprise.js?render=explicit

good to have a prop to enable this handling

DilipTheMystery avatar Oct 07 '21 23:10 DilipTheMystery

Hello, I am also interested to use this plugin with recaptcha enterprise. Is there any news about this ticket? Thanks!

roxanemace avatar Nov 12 '21 13:11 roxanemace

💭 💡 This may be pretty straightforward and able to be backwards compatible.

We could utilize window.recaptchaOptions. https://github.com/dozoisch/react-google-recaptcha/blob/d85b97f70ce95fad40f29c14e463118ff175ee31/src/recaptcha-wrapper.js#L7-L15

Possible approach:

function getOptions() {
  return (typeof window !== "undefined" && window.recaptchaOptions) || {};
}

function getURL() {
  const dynamicOptions = getOptions();
  if (dynamicOptions.recaptchaUrl) {
    return dynamicOptions.recaptchaUrl;
  }
  const hostname = dynamicOptions.useRecaptchaNet ? "recaptcha.net" : "www.google.com";
  return `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit`;
}

Check for a new property on recaptchaOptions called recaptchaUrl and if present use it as the js url. Then users could try to use the enterprise recaptcha.

hartzis avatar Nov 12 '21 22:11 hartzis

And also, for the methods as exposed by the enterprise library like grecaptcha.enterprise.execute, grecaptcha.enterprise.reset and grecaptcha.enterprise.reset, we'll need some changes.

9kartik avatar Dec 22 '21 08:12 9kartik

I created a pull request and tested it against my Enterprise account here.

kuhnsm avatar Jan 05 '22 01:01 kuhnsm

Hey! I faced same problem with libraries not supporting Enterprise Recaptcha, ended up writing own solution: https://gist.github.com/sladg/1e22ffccc7f1b4ec65f08ec0d22bca95

sladg avatar May 11 '23 08:05 sladg