oanhnn / laravel-webhook-shield
Protects against unverified webhooks from 3rd party services on Laravel 5.5+
Requires
- php: ^7.1.3
- illuminate/container: ^5.5|^6.0
- illuminate/support: ^5.5|^6.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0
- phpunit/phpunit: ^6.3|^7.0|^8.0
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-11-12 19:08:05 UTC
README
Protects against unverified webhooks from 3rd party services on Laravel 5.5+
Features
- Supported Laravel 5.5+
- Allow multi services with same driver (Useful for two webhook endpoints of two facebook applications)
- Supported drivers
- Bitbucket
- Github
- Gitlab
- Mailgun
- Shopify
- Trello
- Easy to extend more drivers
Requirements
- php >=7.1.3
- Laravel 5.5+
Laravel 6.0+ required php 7.2+
Installation
Begin by pulling in the package through Composer.
$ composer require oanhnn/laravel-webhook-shield
The package will automatically register itself.
You can publish the config-file with:
$ php artisan vendor:publish --provider=Laravel\WebhookShield\ServiceProvider
Usage
Configure services
In configuration file, you can define services
<?php return [ 'services' => [ 'github' => [ 'driver' => 'github', 'options' => [], ], 'facebook' => [ 'driver' => \Laravel\WebhookShield\Services\Facebook::class, 'options' => [], ], 'custom' => [ 'driver' => 'custom-driver', 'options' => [], ], ], ];
Protects webhook routes
Route::middleware('shield:facebook')->post('/webhook/facebook', 'WebhookController@facebook'); Route::middleware('shield:github')->post('/webhook/facebook', 'WebhookController@github'); Route::middleware('shield:custom')->post('/webhook/custom', 'WebhookController@custom');
Make custom driver
Make a service implement class
<?php namespace App\Services; use Laravel\WebhookShield\Contracts\Service; class CustomService implements Service { // ... }
And register this driver in app/Providers/AppServiceProvider.php
<?php namespace App\Providers; use App\Services\CustomService; use Illuminate\Support\ServiceProvider; use Laravel\WebhookShield\Facades\Shield; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Shield::extend('custom-driver', function ($app, $config) { return new CustomService($config); }); // ... } /** * Register any application services. * * @return void */ public function register() { // ... } }
Changelog
See all change logs in CHANGELOG
Testing
$ git clone git@github.com/oanhnn/laravel-webhook-shield.git /path
$ cd /path
$ composer install
$ composer phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email to Oanh Nguyen instead of using the issue tracker.
Credits
License
This project is released under the MIT License.
Copyright © 2018-2019 Oanh Nguyen.