Last active
December 16, 2015 12:59
-
-
Save 500friends/5438314 to your computer and use it in GitHub Desktop.
node.js implementation of secure 500friends api.
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
var crypto = require('crypto'); | |
var SECRET_KEY = "SECRET_KEY"; // Your secret | |
var params = { email: "CUSTOMER_EMAIL", uuid: "ACCOUNT_ID" }; | |
var keys = []; for (var key in params) { if (params.hasOwnProperty(key)) { keys.push(key) } }; | |
keys.sort(); | |
var string_to_hash = SECRET_KEY; | |
for (var i=0; i<keys.length; i++){ | |
string_to_hash += key[i]+params[key[i]]; | |
} | |
params.sig = crypto.createHash('md5').update(string_to_hash).digest("hex"); | |
var api_url = "http://loyalty.500friends.com/api/enroll.gif?"; | |
for (var key in params) { | |
api_url += key+"="+encodeURIComponent(params[key])+"&"; | |
} | |
console.log(api_url) // Url of the api call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment