Skip to content

👍 Protects against unverified webhooks from 3rd party services

License

Notifications You must be signed in to change notification settings

lemonphp/webhook-shield

Repository files navigation

Webhook Shield

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

Protects against unverified webhooks from 3rd party services.

Features

  • Compatible with PSR-7, PSR-15 and PSR-17
  • No dependencies
  • Supported drivers
    • Bitbucket
    • Facebook
    • Github
    • Gitlab
    • Mailgun
    • Shopify
    • Trello
  • Coding style follow PSR-2, PSR-4

Requirements

  • php >=7.1

Installation

Begin by pulling in the package through Composer.

$ composer require lemonphp/webhook-shield

Usage

Slim 4

  1. Installation Slim application follow link http://www.slimframework.com/docs/v4/start/installation.html

    $ composer require slim/slim slim/psr7 lemonphp/webhook-shield
  2. Make public/index.php with below content

    <?php
    use Lemon\WebhookShield\ServiceProfiles\Facebook;
    use Lemon\WebhookShield\WebhookShieldMiddleware;
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    use Slim\Factory\AppFactory;
    
    require __DIR__ . '/../vendor/autoload.php';
    
    $app = AppFactory::create();
    
    $shield = new WebhookShieldMiddleware(new Facebook('secret'), $app->getResponseFactory());
    
    $app->post('/webhook/facebook', function (Request $req, Response $res, $args) {
         // TODO: Add webhook event to message queue
         return $res->withStatus(200, 'OK');
    })->add($shield);
    
    // other routes
    
    $app->run();

Changelog

See all change logs in CHANGELOG

Testing

$ git clone [email protected]/lemonphp/webhook-shield.git /path
$ cd /path
$ composer install
$ composer test

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 © 2019 LemonPHP Team.