Created
January 19, 2018 22:17
-
-
Save jamiemtdwyer/41302379962fd643fe0f657dbf07230b to your computer and use it in GitHub Desktop.
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
// 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
Modified from https://github.com/nyalex/shopify-generating-api-token-guide/blob/master/generate_token.php