oanhnn / laravel-webhook-shield
保护Laravel 5.5+上的第三方服务未验证的webhook
1.1.0
2019-09-12 06:47 UTC
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-09-12 18:53:16 UTC
README
保护Laravel 5.5+上的第三方服务未验证的webhook
特性
- 支持Laravel 5.5+
- 允许使用相同驱动器的多服务(适用于两个Facebook应用程序的两个webhook端点)
- 支持的驱动器
- Bitbucket
- Github
- Gitlab
- Mailgun
- Shopify
- Trello
- 易于扩展更多驱动器
要求
- php >=7.1.3
- Laravel 5.5+
Laravel 6.0+需要php 7.2+
安装
首先通过Composer拉取包。
$ composer require oanhnn/laravel-webhook-shield
该包将自动注册自己。
您可以使用以下命令发布配置文件
$ php artisan vendor:publish --provider=Laravel\WebhookShield\ServiceProvider
用法
配置服务
在配置文件中,您可以定义服务
<?php return [ 'services' => [ 'github' => [ 'driver' => 'github', 'options' => [], ], 'facebook' => [ 'driver' => \Laravel\WebhookShield\Services\Facebook::class, 'options' => [], ], 'custom' => [ 'driver' => 'custom-driver', 'options' => [], ], ], ];
保护webhook路由
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');
制作自定义驱动器
制作一个实现类服务
<?php namespace App\Services; use Laravel\WebhookShield\Contracts\Service; class CustomService implements Service { // ... }
并在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
测试
$ git clone git@github.com/oanhnn/laravel-webhook-shield.git /path
$ cd /path
$ composer install
$ composer phpunit
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件发送给 Oanh Nguyen,而不是使用问题跟踪器。
致谢
许可证
本项目根据MIT许可证发布。
版权所有 © 2018-2019 Oanh Nguyen。