I am trying to use Dropbox's API, and I got it to successfully send me alerts via webhooks, but now I want to verify the signatures every time they send me an alert.
From dropbox's documentation, they write:
"Every notification request will include a header called X-Dropbox-Signature that includes an HMAC-SHA256 signature of the request body, using your app secret as the signing key. This lets your app verify that the notification really came from Dropbox."
So I successfully catch that signature, and I use NodeJS built in crypto module to try to create my own signature with HMAC SHA256 and then compare my signature against the signature Dropbox sends me.
Here is my code for doing so:
var sign = req.get("X-Dropbox-Signature");
console.log(sign);
var hmac = crypto.createHmac(algorithm, secret);
hmac.update(JSON.stringify(req.body));
hash = hmac.digest('hex');
console.log(hash);
Where algorithm is just 'sha256' and secret is my secret key that I got from my dropbox apps page. I have to use JSON.stringify(req.body) because req.body is an object and hmac.update takes a string. I am wondering if that is where my error comes from?
I console log the sign which is the signature from dropbox, and then I console log the signature which I created using hmac, but it is a different signature.
Any suggestions to what I may be doing wrong?