Last active
October 19, 2020 16:06
-
-
Save summersab/a5bb15e5522ee931055f74b2b7b2a630 to your computer and use it in GitHub Desktop.
SignifyD Webhook JSON Validation (PHP)
This file contains 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 | |
function validatePostedJson() { | |
$json = file_get_contents('php://input'); | |
if ($json == null) { | |
header('HTTP/1.1 400 Bad Request', true, 400); | |
die('No Data Found'); | |
} | |
//Check the Hash | |
if (!isset($_SERVER['HTTP_X_SIGNIFYD_SEC_HMAC_SHA256']) || base64_encode(hex2bin(hash_hmac('sha256', $json, TEAM_API_KEY))) != $_SERVER['HTTP_X_SIGNIFYD_SEC_HMAC_SHA256']) { | |
header('HTTP/1.1 403 Forbidden', true, 403); | |
die('Unauthorized Request'); | |
} | |
//Check Data | |
$data = json_decode($json, 1); | |
if (!is_array($data)) { | |
header('HTTP/1.1 400 Bad Request', true, 400); | |
die('Invalid Data'); | |
} | |
return $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment