Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Verifying X-Fitbit-Signature header in node.js

ANSWERED

Hi,

please, someone can help me with this.
I'm trying to verify the X-Fitbit-Signature (node.js)

      var hmac = crypto.createHmac('sha1', FITBIT_CLIENT_SECRET + '&');
      var requestHash = hmac.update(req.body.toString()).digest('base64');

      if (requestHash !== req.get('x-fitbit-signature')) {

.........

       

something is worng, I never get a succes calculated hmac digest.

I can recieve the notificatios.

 

Best Answer
1 BEST ANSWER

Accepted Solutions

solved 

var data = JSON.stringify(req.body);

var requestHash = hmac.update(data).digest('base64');

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

solved 

var data = JSON.stringify(req.body);

var requestHash = hmac.update(data).digest('base64');

Best Answer
0 Votes

@clarisa: One important detail: You should verify the signature *before* you JSON.parse the request body. JavaScript does not guarantee Object property ordering, which means that the body string sent by the server may not be the same string returned by JSON.stringify.

Best Answer

Many thanks for the recommendation!!! 

Best Answer
0 Votes