diff --git a/app/Client/Callbacks/WebHookConnectionCallback.php b/app/Client/Callbacks/WebHookConnectionCallback.php new file mode 100644 index 0000000..bf33141 --- /dev/null +++ b/app/Client/Callbacks/WebHookConnectionCallback.php @@ -0,0 +1,31 @@ +browser = $browser; + } + + public function handle(ControlConnection $connection) + { + $this->browser->post(config('expose.admin.connection_callbacks.webhook.url'), [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'X-Signature' => $this->generateWebhookSigningSecret($connection), + ], json_encode($connection->toArray())); + } + + protected function generateWebhookSigningSecret(ControlConnection $connection) + { + return hash_hmac('sha256', $connection->client_id, config('expose.admin.connection_callbacks.webhook.secret')); + } +} diff --git a/config/expose.php b/config/expose.php index ae1637a..d64e115 100644 --- a/config/expose.php +++ b/config/expose.php @@ -306,10 +306,18 @@ return [ | | This is a callback method that will be called when a new connection is | established. + | The \App\Client\Callbacks\WebHookConnectionCallback::class is included out of the box. | */ 'connection_callback' => null, + 'connection_callbacks' => [ + 'webhook' => [ + 'url' => null, + 'secret' => null, + ] + ], + /* |-------------------------------------------------------------------------- | Users