From 22c2f090e2dbcbb0dd34f53b388c1e8d95e6fe79 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Tue, 21 Dec 2021 15:50:28 +0100 Subject: [PATCH] Add WebHook connection callback --- .../Callbacks/WebHookConnectionCallback.php | 31 +++++++++++++++++++ config/expose.php | 8 +++++ 2 files changed, 39 insertions(+) create mode 100644 app/Client/Callbacks/WebHookConnectionCallback.php 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