oanhnn/laravel-webhook-shield

Protects against unverified webhooks from 3rd party services on Laravel 5.5+

1.1.0 2019-09-12 06:47 UTC

This package is auto-updated.

Last update: 2024-02-12 17:35:07 UTC


README

Latest Version Software License Build Status Coverage Status Total Downloads Requires PHP

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
    • Facebook
    • 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.