Skip to content

Instantly share code, notes, and snippets.

@williscool
Created February 12, 2015 08:19
Show Gist options
  • Save williscool/0792eb30923e48f46116 to your computer and use it in GitHub Desktop.
Save williscool/0792eb30923e48f46116 to your computer and use it in GitHub Desktop.
referralsaasquatch node.js integration
// this relies or lodash or underscore
// based on algorithm here http://docs.referralsaasquatch.com/squatchjs/signed-requests
var params = req.body;
// delete any null keys http://stackoverflow.com/questions/14058193/remove-empty-properties-falsy-values-from-object-with-underscore-js
var clean_params = _.pick(params, _.identity);
// sort keys and join to add to string
var params_to_sign_string = '' ;
_.forEach(_.keys(clean_params).sort(), function(key_name){
params_to_sign_string += params[key_name];
});
// sign stackoverflow.com/questions/20004530/node-js-hmac-sha256-base64-of-string
var hash = crypto.createHmac('SHA256', config.referralsaasquatch.api_key).update(params_to_sign_string).digest('base64');
var response = {
checksum: hash
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment