We have made an App Proxy and data is being sent to it successfully utilizing an Ajax request.
When I look at the data being sent it shows as a $_GET request:
shop => mydomain.myshopify.com
logged_in_customer_id =>
path_prefix => /apps/share
timestamp => 1668542761
signature => e4b381234fdsaf23rt2fwdsaf23f32fsdb531eda4c4ce81057d60015a742d
I cannot seem to Verify the signature against the client secret.
I am using PHP and have tried many different ways:
function verify_webhook($data, $hmac_header)
{
$ar= [];
$hmac = $data['signature'];
unset($data['signature']);
foreach($data as $key=>$value){
$key=str_replace("%","%25",$key);
$key=str_replace("&","%26",$key);
$key=str_replace("=","%3D",$key);
$value=str_replace("%","%25",$value);
$value=str_replace("&","%26",$value);
$ar[] = $key."=".$value;
}
$str = join('&',$ar);
$ver_hmac = hash_hmac('sha256',$str,SHOPIFY_APP_SECRET,false);
return($ver_hmac==$hmac);
}
Also initially tried this as well:
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return ($hmac_header == $calculated_hmac);
}
Not sure what I am missing.
For the $data am I just sending everything in the $_GET request?