Skip to content

Commit

Permalink
Merge pull request #98 from bezhermoso/url-in-signer
Browse files Browse the repository at this point in the history
Feature Request: Support using webhook URLs as part of webhook signatures
  • Loading branch information
freekmurze authored Sep 10, 2021
2 parents 21292b3 + 5b9e1eb commit 96eacc9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Signer/DefaultSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class DefaultSigner implements Signer
{
public function calculateSignature(array $payload, string $secret): string
public function calculateSignature(string $webhookUrl, array $payload, string $secret): string
{
$payloadJson = json_encode($payload);

Expand Down
2 changes: 1 addition & 1 deletion src/Signer/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface Signer
{
public function signatureHeaderName(): string;

public function calculateSignature(array $payload, string $secret): string;
public function calculateSignature(string $webhookUrl, array $payload, string $secret): string;
}
2 changes: 1 addition & 1 deletion src/WebhookCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function getAllHeaders(): array
return $headers;
}

$signature = $this->signer->calculateSignature($this->payload, $this->secret);
$signature = $this->signer->calculateSignature($this->callWebhookJob->webhookUrl, $this->payload, $this->secret);

$headers[$this->signer->signatureHeaderName()] = $signature;

Expand Down
2 changes: 1 addition & 1 deletion tests/DefaultSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function it_can_calculate_a_signature_for_a_given_payload_and_secret()
{
$signer = new DefaultSigner();

$signature = $signer->calculateSignature(['a' => '1'], 'abc');
$signature = $signer->calculateSignature('https://my.app/webhooks', ['a' => '1'], 'abc');

$this->assertEquals(
'345611a3626cf5e080a7a412184001882ab231b8bdb465dc76dbf709f01f210a',
Expand Down

0 comments on commit 96eacc9

Please sign in to comment.