Created
May 7, 2013 16:56
-
-
Save marfarma/5534213 to your computer and use it in GitHub Desktop.
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 genSignedParamString = function(userID, secret, cmd, params) { | |
params.userid = userID; | |
params.command = cmd; | |
var paramKeys = []; | |
for(var key in params) { | |
if(params.hasOwnProperty(key)){ | |
paramKeys.push(key); | |
}; | |
}; | |
paramKeys.sort(); //you get a cookie if you can tell me why we sort the parameters | |
var qsParameters = []; | |
for(var i = 0; i < paramKeys.length; i++) { | |
key = paramKeys[i]; | |
qsParameters.push(key + '=' + encodeURIComponent(params[key])); | |
} | |
var queryString = qsParameters.join('&') | |
, cryptoAlg = crypto.createHmac('sha1', secret) | |
, signature = cryptoAlg.update(queryString.toLowerCase()).digest('base64'); | |
return queryString + '&signature=' + encodeURIComponent(signature); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment