Created
February 12, 2015 08:19
-
-
Save williscool/0792eb30923e48f46116 to your computer and use it in GitHub Desktop.
referralsaasquatch node.js integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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