How can I fix HMAC validation failure in PHP for a Shopify App?

How can I fix HMAC validation failure in PHP for a Shopify App?

OlegarioF
Visitor
2 0 0

Hello, I need help with the hmac validation, I am creating a Shopify App but to confirm installation I need to add the security checks, the problem is to validate the hmac because the documentation has a Ruby example but I need to do it with PHP, I have been doing many test and always I am getting FALSE after compare the hmacs.

 

Here my code:

 

        $hmac = $params['hmac'];
        $secret = 'hush';
        $uri = $request->getUri();

        //get the queries from the URI
        $queryString = $uri->getQuery();

        //remove the hmac from the query string
        $queryString = str_replace('&hmac='.$hmac, '', $queryString);

        //create the hmac
        $crypted = hash_hmac('sha256', $queryString, $secret);
    
        //verify if the hmacs match
        $validation = hash_equals($crypted, $hmac);

        error_log('VALIDATION '.var_export($validation, true));

 

 

Please help me!

Thanks in advance

Replies 0 (0)