From c3c0ef0529d33b4cbc3ee8ceb12b9d5497a84242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ticho=C5=88?= Date: Mon, 24 Nov 2025 10:19:09 +0100 Subject: [PATCH] - Add support for reCAPTCHA v3 Enterprise in README and implementation - Introduce configurable endpoint for enterprise users - Enhance Livewire directive with reCAPTCHA enterprise integration --- README.md | 20 +++++++------ src/ValidatesRecaptcha.php | 4 ++- ...irective.recaptcha.v3-enterprise.blade.php | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100755 src/directive.recaptcha.v3-enterprise.blade.php diff --git a/README.md b/README.md index 4935fd5..31ae338 100755 --- a/README.md +++ b/README.md @@ -22,11 +22,12 @@ version you are going to implement. This package supports the following versions. Note that each version requires a different sitekey/secretkey pair: -| **Version** | **Docs** | **Notes** | -|----------------------|-------------------------------------------------------------------|-----------------------------| -| **v3** (recommended) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | | -| **v2** | [V2 Docs](https://developers.google.com/recaptcha/docs/display) | | -| **v2 invisible** | [V2 Docs](https://developers.google.com/recaptcha/docs/invisible) | Use `'size' => 'invisible'` | +| **Version** | **Docs** | **Notes** | +|----------------------|-------------------------------------------------------------------|-----------------------------------| +| **v3** (recommended) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | | +| **v3** (enterprise) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | Use `'version' => 'v3-enterprise'` | +| **v2** | [V2 Docs](https://developers.google.com/recaptcha/docs/display) | | +| **v2 invisible** | [V2 Docs](https://developers.google.com/recaptcha/docs/invisible) | Use `'size' => 'invisible'` | Your options should reside in the `config/services.php` file: @@ -38,6 +39,7 @@ Your options should reside in the `config/services.php` file: 'secret_key' => env('GOOGLE_RECAPTCHA_SECRET_KEY'), 'version' => 'v3', 'score' => 0.5, // An integer between 0 and 1, that indicates the minimum score to pass the Captcha challenge. + 'endpoint' => 'https://www.google.com/recaptcha/api/siteverify', // For enterprise users, fill in your URL from google console (https://recaptchaenterprise.googleapis.com/v1/projects/project-name/assessments?key=API_KEY ], ], @@ -113,10 +115,10 @@ You can override any of the configuration values using: ```html @livewireRecaptcha( - version: 'v2', - siteKey: 'abcd_efgh-hijk_LMNOP', - theme: 'dark', - size: 'compact', +version: 'v2', +siteKey: 'abcd_efgh-hijk_LMNOP', +theme: 'dark', +size: 'compact', ) ``` diff --git a/src/ValidatesRecaptcha.php b/src/ValidatesRecaptcha.php index 345e7e9..fb66c2e 100755 --- a/src/ValidatesRecaptcha.php +++ b/src/ValidatesRecaptcha.php @@ -16,9 +16,11 @@ class ValidatesRecaptcha extends LivewireAttribute public function __construct( public ?string $secretKey = null, public ?float $score = null, + public ?string $endpoint = null, ) { $this->secretKey ??= config('services.google.recaptcha.secret_key'); $this->score ??= config('services.google.recaptcha.score') ?? 0.5; + $this->endpoint ??= config('services.google.recaptcha.endpoint', 'https://www.google.com/recaptcha/api/siteverify'); } /** @@ -29,7 +31,7 @@ public function __construct( public function call(array $params, Closure $returnEarly): void { if (isset($this->component->gRecaptchaResponse)) { - $response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [ + $response = Http::asForm()->post($this->endpoint, [ 'secret' => $this->secretKey, 'response' => $this->component->gRecaptchaResponse, 'remoteip' => request()->ip(), diff --git a/src/directive.recaptcha.v3-enterprise.blade.php b/src/directive.recaptcha.v3-enterprise.blade.php new file mode 100755 index 0000000..5fe16b1 --- /dev/null +++ b/src/directive.recaptcha.v3-enterprise.blade.php @@ -0,0 +1,29 @@ + +