Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixel-open/cloudflare-turnstile-bundle
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
https://github.com/pixel-open/cloudflare-turnstile-bundle
cloudflare recaptcha symfony-bundle turnstile
Last synced: 1 day ago
JSON representation
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
- Host: GitHub
- URL: https://github.com/pixel-open/cloudflare-turnstile-bundle
- Owner: Pixel-Open
- License: mit
- Created: 2022-10-01T10:34:56.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-30T15:44:13.000Z (4 months ago)
- Last Synced: 2024-10-30T00:33:05.695Z (3 months ago)
- Topics: cloudflare, recaptcha, symfony-bundle, turnstile
- Language: PHP
- Homepage: https://pixel-open.org/projects/symfony-bundle-cloudflare-turnstile/
- Size: 77.1 KB
- Stars: 23
- Watchers: 1
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
A simple package to help integrate Cloudflare Turnstile on Symfony Form.
======================[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-green)](https://php.net/)
[![Minimum Symfony Version](https://img.shields.io/badge/symfony-%3E%3D%205.4-green)](https://symfony.com)
[![GitHub release](https://img.shields.io/github/v/release/Pixel-Open/cloudflare-turnstile-bundle)](https://github.com/Pixel-Open/cloudflare-turnstile-bundle/releases)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Pixel-Open_cloudflare-turnstile-bundle&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Pixel-Open_cloudflare-turnstile-bundle)This packages provides helper for setting up and validating Cloudflare Turnstile CAPTCHA responses.
![Cloudflare Turnstile for Symfony Form](screenshot.png)
## Installation
You can install the package via Composer:
```bash
composer require pixelopen/cloudflare-turnstile-bundle
```Add bundle into config/bundles.php file :
```php
PixelOpen\CloudflareTurnstileBundle\PixelOpenCloudflareTurnstileBundle::class => ['all' => true]
```
Add a config file into config/packages/pixel_open_cloudflare_turnstile.yaml :```yaml
pixel_open_cloudflare_turnstile:
key: '%env(TURNSTILE_KEY)%'
secret: '%env(TURNSTILE_SECRET)%'
enable : true
```Visit Cloudflare to create your site key and secret key and add them to your `.env` file.
```
TURNSTILE_KEY="1x00000000000000000000AA"
TURNSTILE_SECRET="2x0000000000000000000000000000000AA"
```### Use with your Symfony Form
Create a form type and insert an Turnstile Type to add a Cloudflare Turnstile :
```php
add('name', TextType::class, ['label' => false, 'attr' => ['placeholder' => 'name']])
->add('message', TextareaType::class, ['label' => false, 'attr' => ['placeholder' => 'message']])
->add('security', TurnstileType::class, ['attr' => ['data-action' => 'contact', 'data-theme' => 'dark'], 'label' => false])
->add('submit', SubmitType::class)
;
}public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}
```### Testing
Use the following sitekeys and secret keys for testing purposes:
**Sitekey**
| Sitekey | Description |
|--------------------------|---------------------------------|
| 1x00000000000000000000AA | Always passes |
| 2x00000000000000000000AB | Always blocks |
| 3x00000000000000000000FF | Forces an interactive challenge |**Secret key**
| Secret key | Description |
|-------------------------------------|--------------------------------------|
| 1x0000000000000000000000000000000AA | Always passes |
| 2x0000000000000000000000000000000AA | Always fails |
| 3x0000000000000000000000000000000AA | Yields a "token already spent" error |## Todo
+ Add phpunit to test field ~~and validator~~
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.