Skip to content

Commit 4d19f07

Browse files
author
Robert Wittman
committed
Added HMAC validation
1 parent 136f1b8 commit 4d19f07

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/Shopify.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ public static function __callStatic($method, $args)
194194
throw new Exception\ApiException("Call to undefined function {$method}");
195195
}
196196

197+
/**
198+
* Verify that HMAC hash of parameters matches HMAC signature
199+
* @return [type] [description]
200+
*/
201+
public static function validateHmac()
202+
{
203+
$params = [];
204+
foreach($_GET as $param => $value) {
205+
if ($param != 'signature' && $param != 'hmac') {
206+
$params[$param] = "{$param}={$value}";
207+
}
208+
}
209+
asort($params);
210+
$params = implode("&", $params);
211+
212+
return $_GET['hmac'] === hash_hmac('sha256', $params, self::$api_secret);
213+
}
214+
197215
/**
198216
* Return the root API url based on the authenticated store
199217
* @return string

0 commit comments

Comments
 (0)