Merge pull request #15 from isocolsky/http_method

add http method to request signature
This commit is contained in:
Matias Alejo Garcia 2015-02-15 11:33:47 -03:00
commit 864b45f098
2 changed files with 7 additions and 7 deletions

2
app.js
View File

@ -83,7 +83,7 @@ function getServerWithAuth(req, res, cb) {
var credentials = getCredentials(req);
var auth = {
copayerId: credentials.copayerId,
message: req.url + '|' + JSON.stringify(req.body),
message: req.method.toLowerCase() + '|' + req.url + '|' + JSON.stringify(req.body),
signature: credentials.signature,
};
CopayServer.getInstanceWithAuth(auth, function(err, server) {

View File

@ -38,8 +38,8 @@ function _parseError(body) {
log.error(code, message);
};
function _signRequest(url, args, privKey) {
var message = url + '|' + JSON.stringify(args);
function _signRequest(method, url, args, privKey) {
var message = method.toLowerCase() + '|' + url + '|' + JSON.stringify(args);
return SignUtils.sign(message, privKey);
};
@ -83,16 +83,16 @@ ClientLib.prototype._loadAndCheck = function() {
}
return data;
};
ClientLib.prototype._doRequest = function(type, url, args, data, cb) {
var reqSignature = _signRequest(url, args, data.signingPrivKey);
ClientLib.prototype._doRequest = function(method, url, args, data, cb) {
var reqSignature = _signRequest(method, url, args, data.signingPrivKey);
var absUrl = _getUrl(url);
request({
headers: {
'x-identity': data.copayerId,
'x-signature': reqSignature,
},
method: type,
method: method,
url: absUrl,
body: args,
json: true,