Skip to content

Commit 0d17ef8

Browse files
authored
Merge pull request #4 from binary-cats/fix/signature-validation
Fix signature validator
2 parents dd8ccd1 + 798e0be commit 0d17ef8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/LobSignatureValidator.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@ class LobSignatureValidator implements SignatureValidator
3434
public function isValid(Request $request, WebhookConfig $config): bool
3535
{
3636
$signatureArray = [
37-
'token' => json_encode($request->all()),
38-
'timestamp' => $request->header('lob-signature-timestamp'),
39-
'signature' => $request->header('lob-signature'),
37+
'token' => $this->payload($request),
38+
'timestamp' => $request->header('lob-signature-timestamp'),
39+
'signature' => $request->header('lob-signature'),
4040
];
4141

4242
$secret = $config->signingSecret;
4343

4444
try {
45-
Webhook::constructEvent($request->all(), $signatureArray, $secret);
45+
Webhook::constructEvent($request->input(), $signatureArray, $secret);
4646
} catch (Exception $exception) {
4747
return false;
4848
}
4949

5050
return true;
5151
}
52+
53+
/**
54+
* Compile the payload.
55+
*
56+
* @param Illuminate\Http\Request $request
57+
* @return string
58+
*/
59+
protected function payload(Request $request): string
60+
{
61+
// Will decode the body into an object, not an array
62+
$decoded = json_decode($request->getContent());
63+
// recode back into string
64+
return json_encode($decoded, JSON_UNESCAPED_SLASHES);
65+
}
5266
}

0 commit comments

Comments
 (0)