Skip to content

Instantly share code, notes, and snippets.

@summersab
Last active October 19, 2020 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save summersab/a5bb15e5522ee931055f74b2b7b2a630 to your computer and use it in GitHub Desktop.
Save summersab/a5bb15e5522ee931055f74b2b7b2a630 to your computer and use it in GitHub Desktop.
SignifyD Webhook JSON Validation (PHP)
<?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