Skip to content

Commit 23576a6

Browse files
committed
New HMAC Validation
1 parent 645b642 commit 23576a6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/RocketCode/Shopify/api.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ public function verifyRequest($data = NULL, $bypassTimeCheck = FALSE)
5858
}
5959
}
6060

61-
$signature = $da['signature'];
62-
unset($da['signature']);
63-
ksort($da);
64-
65-
66-
$queryString = http_build_query($da, NULL, '');
67-
68-
$calculated = md5($this->_API['API_SECRET'] . $queryString);
61+
if (array_key_exists('hmac', $da))
62+
{
63+
// HMAC Validation
64+
$queryString = http_build_query(array('code' => $da['code'], 'shop' => $da['shop'], 'timestamp' => $da['timestamp']));
65+
$match = $da['hmac'];
66+
$calculated = hash_hmac('sha256', $queryString, $this->_API['API_SECRET']);
67+
}
68+
else
69+
{
70+
// MD5 Validation, to be removed June 1st, 2015
71+
$queryString = http_build_query(array('code' => $da['code'], 'shop' => $da['shop'], 'timestamp' => $da['timestamp']), NULL, '');
72+
$match = $da['signature'];
73+
$calculated = md5($this->_API['API_SECRET'] . $queryString);
74+
}
6975

70-
return $calculated === $signature;
76+
return $calculated === $match;
7177
}
7278

7379
/**

0 commit comments

Comments
 (0)