artack/recaptcha-enterprise-bundle
FormRequest, Validator) differs from Symfony’s FormBuilder. The bundle’s form-type integration would require custom Laravel form components (e.g., Livewire, Inertia.js, or manual HTML/JS handling) or a wrapper service to replicate its behavior.0.1.*).FormRequest rules or Livewire components).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Breaking Changes | High | Pin to 0.1.*, monitor GitHub issues. |
| Symfony Dependency | Medium | Abstract dependencies (e.g., use Guzzle for HTTP). |
| Form Integration | High | Build Laravel-specific wrappers or use Livewire. |
| Validation Overhead | Low | Cache API responses; batch validate tokens. |
| CSP/JS Conflicts | Medium | Test with Laravel’s CSP middleware. |
| Laravel Component | Bundle Compatibility | Workaround Needed |
|---|---|---|
| Form Requests | Low | Replace RecaptchaEnterpriseType with custom FormRequest rules. |
| Validation | Medium | Adapt RecaptchaEnterprise constraint to Laravel’s Validator. |
| Blade Templating | Low | Replace Twig themes with Blade or JS. |
| HTTP Client | High | Use Laravel’s Http facade or Guzzle. |
| Environment Config | High | Use Laravel’s .env + config/services.php. |
| Livewire/Inertia | High | Ideal for JS-based form integration. |
Phase 1: Core Validation Logic
// app/Services/RecaptchaEnterpriseValidator.php
class RecaptchaEnterpriseValidator {
public function validateToken(string $token, string $action, float $minScore): bool {
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config('services.recaptcha.api_key'),
])->post('https://recaptchaenterprise.googleapis.com/v1/projects/' .
config('services.recaptcha.project_id') . '/assessments', [
'event' => [
'token' => $token,
'siteKey' => config('services.recaptcha.site_key'),
'expectedAction' => $action,
],
]);
$data = $response->json();
return $data['score'] >= $minScore;
}
}
AppServiceProvider:
$this->app->singleton(RecaptchaEnterpriseValidator::class, function ($app) {
return new RecaptchaEnterpriseValidator();
});
Phase 2: Form Integration
// app/Http/Livewire/ContactForm.php
public function submit() {
$validator = app(RecaptchaEnterpriseValidator::class);
if (!$validator->validateToken($this->recaptchaToken, 'contact', 0.7)) {
throw ValidationException::withMessages(['recaptcha' => 'Invalid token.']);
}
// Proceed...
}
<script src="https://www.gstatic.com/recaptcha/api.js?render={{ config('services.recaptcha.site_key') }}"></script>
// app/Http/Requests/ContactRequest.php
use App\Rules\RecaptchaEnterprise as RecaptchaRule;
public function rules() {
return [
'recaptcha_token' => [new RecaptchaRule(0.7, 'contact')],
];
}
// app/Rules/RecaptchaEnterprise.php
class RecaptchaEnterprise implements Rule {
public function passes($attribute, $value) {
return app(RecaptchaEnterpriseValidator::class)
->validateToken($value, $this->action, $this->minScore);
}
}
Phase 3: Configuration
config/services.php:
'recaptcha' => [
'enabled' => env('RECAPTCHA_ENABLED', true),
'site_key' => env('RECAPTCHA_SITE_KEY'),
'project_id' => env('RECAPTCHA_PROJECT_ID'),
'api_key' => env('RECAPTCHA_API_KEY'),
'min_score' => 0.5,
],
.env for dev:
RECAPTCHA_ENABLED=false
ContentSecurityPolicy middleware to ensure grecaptcha script loads./api/test-recaptcha).| Task | Effort | Owner |
|---|---|---|
| Dependency Updates | Low | DevOps |
| Configuration Management | Medium | TPM/Backend Engineer |
| Validation Logic | Low | Backend Engineer |
| Form/JS Updates | Medium | Frontend Engineer |
| API Key Rotation | Low | Security Team |
How can I help you explore Laravel packages today?