Custom app - SHA256 PHP and JavaScript not equal

Hi.

I am trying to confirm the app registration within a JS App instead of a PHP App. Currently I am desperately searching for the right way to parse the body I receive from PHP.

Maybe you can give an example of a Body from App Base Guide - Shopware Developer

Here is my Code and outcome:


 var obj = JSON.parse(data); //now it an object
 const encryption_token = all_tokens[shopid];
 console.log(JSON.stringify(req.body, null, 2))
// {
//   "apiKey": "SWIAVZQZSXJSTVZKBKFQA1FQVQ",
//   "secretKey": "R2VVQTJSY21YUFVpaGRJcWZuY3A2T0kyWDhFa1VZZ2VTSHV6Rkc",
//   "timestamp": "1627734129",
//   "shopUrl": "http://localhost",
//   "shopId": "zISDYSSSAlNOp5cp"
// }
 const our_encryption = hmacSHA256(
                Latin1.parse(JSON.stringify(req.body, null, 2)), // use two letter spacing in JSON
                Latin1.parse(encryption_token)
            ).toString();
 console.log(our_encryption);
// d023f9b2d48e49fd8150920138afbaa1b00254a9e1b6fd329fda9975cb39b1ef
 console.log(signature);
//2ab5c057138f8dfc8f97aad1dc9b0d05599eac77aec8b0833472d1a136a0cdf8

I already tried with 4 and 0 spaces in JSON.stringify. Same result

Any possible solution?

Solved. PHP uses some weird \ before any /.

This could be solved by using only the raw body.