Last active
September 18, 2024 21:10
-
-
Save it-can/f237f84dd4e115b4628be10233f2c138 to your computer and use it in GitHub Desktop.
webhook validation mailpace laravel/php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Retrieve the signature from the request headers and decode it from base64 | |
$signature_base64 = $request->header('X-MailPace-Signature'); | |
$signature = base64_decode($signature_base64); | |
if ($signature === false) { | |
// Invalid signature encoding | |
abort(400, 'Invalid signature encoding'); | |
} | |
// Decode your public key from base64 | |
$verify_key_base64 = 'Your Public Key from app.mailpace.com here'; | |
$verify_key = base64_decode($verify_key_base64); | |
if ($verify_key === false) { | |
// Invalid public key encoding | |
abort(500, 'Invalid public key encoding'); | |
} | |
// Retrieve the raw body of the request | |
$message = $request->getContent(); | |
// Verify the signature | |
$isValid = sodium_crypto_sign_verify_detached($signature, $message, $verify_key); | |
if ($isValid) { | |
// Verification passed | |
return response('Verification passed', 200); | |
} else { | |
// Verification failed | |
abort(400, 'Invalid signature'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this should work:
$message = json_encode($response->getOriginalContent(), JSON_HEX_TAG);
Try that and let me know if you still face problems