我已经配置了一个webhook,当事件在应用程序中发生时,url被调用,但我在调用中没有获得任何数据。

根据它的文档

为了增加安全性,发送到OAuth授权应用程序的webhooks被签名,因此它们可以被验证为源自供应商,并且在运输过程中未被更改。基于散列的消息认证码用于签名。如果webhook请求包含如下标题,则应用程序可以验证该请求。
X-Signature: signature=897hRT893qkA783M093ha903f,algorithm=HMAC-SHA256为此,请通过对webhook请求正文进行散列来生成签名,并将其与头部中的签名进行比较,以获得精确匹配。使用标头中指定的算法和应用程序的client_secret作为散列键。
参考- https://docs.vendhq.com/tutorials/guides/webhooks/introduction
我有密钥,但是我不确定如何通过散列webhook请求主体来生成签名?
有什么想法吗?
谢谢你
发布于 2021-01-12 14:21:35
Ok联系了Vend,并解决了这个问题:
首先,只有当你通过Oauth授权的应用程序创建webhook时,这才有效。并使用您自己的client_secret向Vend发送X-Signature和带有curl的webhook创建请求,如下所示:
$token = 'Authorization: Bearer ' . get_option('vend_token');
$client_secret = get_option("client_secret");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'X-Signature: signature='.$client_secret.',algorithm=HMAC-SHA256',
'Content-Type: application/x-www-form-urlencoded', $token ));然后,在回调函数中:
function receive_webhook_callback( $request_data){
$data = $request_data->get_body();
$client_secret = get_option("client_secret");
$signaturehash = hash_hmac('sha256', $data, $client_secret, false);
$signature = "signature=".$signaturehash.", algorithm=HMAC-SHA256";
error_log('signature:');
error_log($signature);
$sig_header = $_SERVER['HTTP_X_SIGNATURE'];
error_log('header-signature:');
error_log($sig_header);
if($signature === $sig_header) {
error_log("signatures match!!");
}
} 发布于 2021-01-13 00:09:42
查看示例X-Signature标头,它提供了算法:
algorithm=HMAC-SHA256,
X签名: signature=897hRT893qkA783M093ha903f
来自PHP: How can I generate a HmacSHA256 signature of a string
使用hash_hmac:
$sig = hash_hmac('sha256',$string,$secret)
其中$secret是你的钥匙。
其中$string将是webhook主体。
https://stackoverflow.com/questions/65519754
复制相似问题