t49tran / react-google-recaptcha-v3

Google Recaptcha V3 integration for React
MIT License
427 stars 91 forks source link

Action value is empty #113

Open dhyey-talkdoc opened 2 years ago

dhyey-talkdoc commented 2 years ago

I use the following code in the frontend to generate a new token upon user action

    if (!executeRecaptcha) {
      console.log('Execute Recaptcha not yet available');
      return;
    } else {
      await executeRecaptcha('login').then(token => recaptchaToken = token);
    }
  };

On the backend, I get the response from an assessment using this code:

        url = 'https://recaptchaenterprise.googleapis.com/v1beta1/projects/{0}/assessments?key={1}'.format(
           RECAPTCHA_PROJECT_ID, RECAPTCHA_API_KEY)

        data = {
            "event": {
                "token": token,
                "siteKey": SITEKEY,
                "expectedAction": 'login'
            }
        }

        response = requests.post(url, data = json.dumps(data))
        content = json.loads(response.content)

What I see is that sometimes, content['tokenProperties']['action'] is blank, and the score is 0, even though the FE is sending the action. This only happens sometimes, not every time.

Any inputs on whether I'm doing anything wrong?