PHPackages                             settermjd/twilio-eventstreams-webhook-validator-slim - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. settermjd/twilio-eventstreams-webhook-validator-slim

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

settermjd/twilio-eventstreams-webhook-validator-slim
====================================================

Slim middleware for validating Twilio Event Streams Webhooks

0.0.2(1y ago)14BSD-3-ClausePHPPHP ~8.3.0

Since Sep 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/settermjd/twilio-eventstreams-webhook-validator-slim)[ Packagist](https://packagist.org/packages/settermjd/twilio-eventstreams-webhook-validator-slim)[ Fund](https://funding.communitybridge.org/projects/laminas-project)[ RSS](/packages/settermjd-twilio-eventstreams-webhook-validator-slim/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Slim v4 Twilio Event Streams Webhook Validator Middleware
=========================================================

[](#slim-v4-twilio-event-streams-webhook-validator-middleware)

[![testing workflow](https://github.com/settermjd/twilio-eventstreams-webhook-validator-slim/actions/workflows/php.yml/badge.svg)](https://github.com/settermjd/twilio-eventstreams-webhook-validator-slim/actions/workflows/php.yml/badge.svg)

This is a small piece of middleware for [the Slim Framework (v4)](https://www.slimframework.com/) that validates a [Twilio Event Streams Webhook](https://www.twilio.com/docs/events/webhook-quickstart).

How Does It Work?
-----------------

[](#how-does-it-work)

After adding the middleware to one or more of your application's routes, when a route is dispatched, the webhook is validated. If the webhook *is* valid, the next request is called. Otherwise, an [HTTP 400 Bad Request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400) is returned, along with a [problem details](https://datatracker.ietf.org/doc/html/rfc7807) response, formatted as JSON or XML based on the request's [Accept header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept).

Why Use It?
-----------

[](#why-use-it)

You could code up the functionality yourself; and [check out the tutorial on the Twilio blog](https://www.twilio.com/en-us/blog/validate-twilio-event-streams-webhooks-php) if you'd like to. But, this middleware avoids the need to do so. Instead, just initialise it and add it to the relevant routes, then focus on the remaining functionality of your application.

Prerequisites
-------------

[](#prerequisites)

To use this middleware, you're going to need a Twilio account (either free or paid). If you are new to Twilio, [create a free account](https://www.twilio.com/referral/QlBtVJ).

⚡️ Quick Start
--------------

[](#️-quick-start)

To use the middleware in your Slim (v4) application, first add the project as a dependency by running the following command:

```
composer require settermjd/twilio-eventstreams-webhook-validator-slim
```

Then, in the appropriate part of your application, initialise a new `EventStreams\EventStreamsWebhookValidatorMiddleware` object, which requires three parameters:

- The application's public URI. During development you could use [ngrok](https://ngrok.com/) to expose the application to the public internet and generate the public URI.
- The webhook URI's path
- A `\Twilio\Security\RequestValidator` object, initialised with your [Twilio Auth Token](https://help.twilio.com/articles/223136027-Auth-Tokens-and-How-to-Change-Them)

**Note:** The first two parameters to `EventStreamsWebhookValidatorMiddleware` ensure that the app's correct public URI is used as part of the webhook validation process.

Then, follow [the Slim Middleware documentation](https://www.slimframework.com/docs/v4/concepts/middleware.html#registering-middleware) to add the middleware to the respective route. Below, you can find examples of adding it as [Route Middleware](https://www.slimframework.com/docs/v4/concepts/middleware.html#route-middleware):

```
