Skip to content

Instantly share code, notes, and snippets.

@jamiemtdwyer
Created January 19, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamiemtdwyer/41302379962fd643fe0f657dbf07230b to your computer and use it in GitHub Desktop.
Save jamiemtdwyer/41302379962fd643fe0f657dbf07230b to your computer and use it in GitHub Desktop.
// Set variables for our request
$shared_secret = "TBB5wltKarRtKn5mUVZck9RxHePNN6Jo";
$params = $_GET; // Retrieve all request parameters
$hmac = $_GET['hmac']; // Retrieve HMAC request parameter
$params = array_diff_key($params, array('hmac' => '')); // Remove hmac from params
ksort($params); // Sort params lexographically
// Compute SHA256 digest
$computed_hmac = hash_hmac('sha256', http_build_query($params), $shared_secret);
// Use hmac data to check that the response is from Shopify or not
if (hash_equals($hmac, $computed_hmac)) {
// VALIDATED
} else {
// NOT VALIDATED – Someone is trying to be shady!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment