Skip to content

Commit a19aa64

Browse files
authored
Webhook Authenticator (#232)
* Add custom class
1 parent fd5489c commit a19aa64

24 files changed

Lines changed: 80 additions & 797 deletions

src/Auth/NullAuthenticator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Workflow\Auth;
6+
7+
use Illuminate\Http\Request;
8+
9+
class NullAuthenticator implements WebhookAuthenticator
10+
{
11+
public function validate(Request $request): bool
12+
{
13+
return true;
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Workflow\Auth;
6+
7+
use Illuminate\Http\Request;
8+
9+
class SignatureAuthenticator implements WebhookAuthenticator
10+
{
11+
public function validate(Request $request): bool
12+
{
13+
return hash_equals(
14+
$request->header(config('workflows.webhook_auth.signature.header')) ?? '',
15+
hash_hmac('sha256', $request->getContent(), config('workflows.webhook_auth.signature.secret'))
16+
);
17+
}
18+
}

src/Auth/TokenAuthenticator.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Workflow\Auth;
6+
7+
use Illuminate\Http\Request;
8+
9+
class TokenAuthenticator implements WebhookAuthenticator
10+
{
11+
public function validate(Request $request): bool
12+
{
13+
return $request->header(config('workflows.webhook_auth.token.header')) === config(
14+
'workflows.webhook_auth.token.token'
15+
);
16+
}
17+
}

src/Auth/WebhookAuthenticator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Workflow\Auth;
6+
7+
use Illuminate\Http\Request;
8+
9+
interface WebhookAuthenticator
10+
{
11+
public function validate(Request $request): bool;
12+
}

src/Listeners/MonitorActivityCompleted.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Listeners/MonitorActivityFailed.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Listeners/MonitorActivityStarted.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Listeners/MonitorWorkflowCompleted.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Listeners/MonitorWorkflowFailed.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Listeners/MonitorWorkflowStarted.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)