You are here

function _recaptcha_v3_verify_captcha_response in reCAPTCHA v3 8

Verify captcha response.

Parameters

\Drupal\recaptcha_v3\ReCaptchaV3ActionInterface $recaptcha_v_3_action: Fetch the recaptcha v3 action.

string $captcha_response: Captcha response token.

Return value

array Return the response from google recaptcha api.

1 call to _recaptcha_v3_verify_captcha_response()
recaptcha_v3_validate in ./recaptcha_v3.module
CAPTCHA Callback; Validates the reCAPTCHA v3 code.

File

./recaptcha_v3.module, line 310
Contains recaptcha_v3.module.

Code

function _recaptcha_v3_verify_captcha_response(ReCaptchaV3ActionInterface $recaptcha_v_3_action, $captcha_response) {
  $request = Drupal::request();
  $config = Drupal::config('recaptcha_v3.settings');
  $recaptcha = new ReCaptcha($config
    ->get('secret_key'), function_exists('curl_version') ? new CurlPost() : null);
  if ($config
    ->get('verify_hostname')) {
    $recaptcha
      ->setExpectedHostname($request
      ->getHost());
  }
  return $recaptcha
    ->setExpectedAction($recaptcha_v_3_action
    ->id())
    ->setScoreThreshold($recaptcha_v_3_action
    ->getThreshold())
    ->verify($captcha_response, $request
    ->getClientIp())
    ->toArray();
}