Add WebHook connection callback

This commit is contained in:
Marcel Pociot
2021-12-21 15:50:28 +01:00
parent d34f6d1300
commit 22c2f090e2
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Client\Callbacks;
use App\Server\Connections\ControlConnection;
use Clue\React\Buzz\Browser;
class WebHookConnectionCallback
{
/** @var Browser */
protected $browser;
public function __construct(Browser $browser)
{
$this->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'));
}
}