每当 smartsheet 向我的回调 URL 发出 POST 请求时,我都会尝试验证 Smartsheet 的 Webhook API。以前有人用过这个吗?
每当对我的回调 URL 进行调用时,我都需要验证 POST 请求是否来自 Smartsheet。
按照这里的指南:
To authenticate a callback request:
1. Calculate the HMAC of the webhook's sharedSecret and the request body.
This must be done using the SHA-256 cryptographic hash algorithm.
2. Format the calculated value as a string in base 16.
3. Compare your result with the value of the Smartsheet-Hmac-SHA256 header of the request.
我正在使用 Javascript。我能够生成一个哈希。我尝试了几种方法,但都没有奏效。根据最佳实践和我之前的工作,这应该有效:
crypto.createHash('sha256', sharedSecret).update(JSON.stringify(body)).digest('hex');
但事实并非如此,我什至也试过这个:
crypto.createHash('sha256').update(sharedSecret+JSON.stringify(body)).digest('hex');
它不工作。
这里的 body 变量来自 req.body,来自 Smartsheet 发送到我的回调 URL 的有效负载,sharedSecret 是 Smartsheet 在我创建 webhook 时提供的秘密。