mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Add WebHook connection callback
This commit is contained in:
31
app/Client/Callbacks/WebHookConnectionCallback.php
Normal file
31
app/Client/Callbacks/WebHookConnectionCallback.php
Normal 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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -306,10 +306,18 @@ return [
|
|||||||
|
|
|
|
||||||
| This is a callback method that will be called when a new connection is
|
| This is a callback method that will be called when a new connection is
|
||||||
| established.
|
| established.
|
||||||
|
| The \App\Client\Callbacks\WebHookConnectionCallback::class is included out of the box.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
'connection_callback' => null,
|
'connection_callback' => null,
|
||||||
|
|
||||||
|
'connection_callbacks' => [
|
||||||
|
'webhook' => [
|
||||||
|
'url' => null,
|
||||||
|
'secret' => null,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Users
|
| Users
|
||||||
|
|||||||
Reference in New Issue
Block a user