I'm trying to follow the steps Mandrill has outlined here http://help.mandrill.com/entries/23704122-Authenticating-webhook-requests in order to validate incoming requests. I've setup a test requestb.in with the url seen in the code. I want this method to return the mandrill signature, which in this case is H7Zky1B/GShKH4kuQcfUhNrQq+k= but instead it returns a different value each time. Where am I going wrong?
php code sample as provided by mandrill
function generateSignature($webhook_key, $url, $params) {
$signed_data = $url;
ksort($params);
foreach ($params as $key => $value) {
$signed_data .= $key;
$signed_data .= $value;
}
return base64_encode(hash_hmac('sha1', $signed_data, $webhook_key, true));
}
my ruby code
def valid?(params)
wh_key = "Ny_lzk4zxENbNVezqECBxw"
url = "http://requestb.in/15wvu0y1"
signed_data = url
params.sort.each do |key, value|
signed_data += (key.to_s + value.to_s)
end
digest = OpenSSL::Digest.new('sha1')
Base64.encode64("#{OpenSSL::HMAC.digest(digest,signed_data,wh_key)}")
end