Skip to content

Commit

Permalink
Merge pull request mashery#14 from jplock/master
Browse files Browse the repository at this point in the history
Simplified dependencies by using built-in modules. The package.json will be updated shortly based on the pull request from nathanwdavis made the other day.
  • Loading branch information
mansilladev committed Mar 27, 2012
2 parents 67fe959 + 166b3c7 commit ef0abc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 13 additions & 8 deletions app.js
Expand Up @@ -27,21 +27,20 @@
var express = require('express'),
util = require('util'),
fs = require('fs'),
sys = require('sys'),
OAuth = require('oauth').OAuth,
query = require('querystring'),
url = require('url'),
http = require('http'),
crypto = require('crypto'),
redis = require('redis'),
RedisStore = require('connect-redis')(express),
hashlib = require('hashlib');
RedisStore = require('connect-redis')(express);

// Configuration
try {
var configJSON = fs.readFileSync(__dirname + "/config.json");
var config = JSON.parse(configJSON.toString());
} catch(e) {
sys.puts("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
console.error("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
process.exit(1);
}

Expand Down Expand Up @@ -311,7 +310,7 @@ function processRequest(req, res, next) {
privateReqURL = apiConfig.protocol + '://' + apiConfig.baseURL + apiConfig.privatePath + methodURL + ((paramString.length > 0) ? '?' + paramString : ""),
options = {
headers: {},
protocol: apiConfig.protocol,
protocol: apiConfig.protocol + ':',
host: baseHostUrl,
port: baseHostPort,
method: httpMethod,
Expand Down Expand Up @@ -470,21 +469,27 @@ function processRequest(req, res, next) {

// Add API Key to params, if any.
if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
options.path += '&' + apiConfig.keyParam + '=' + apiKey;
if (options.path.indexOf('?') !== -1) {
options.path += '&';
}
else {
options.path += '?';
}
options.path += apiConfig.keyParam + '=' + apiKey;
}

// Perform signature routine, if any.
if (apiConfig.signature) {
if (apiConfig.signature.type == 'signed_md5') {
// Add signature parameter
var timeStamp = Math.round(new Date().getTime()/1000);
var sig = hashlib.md5('' + apiKey + apiSecret + timeStamp + '', { asString: true });
var sig = crypto.createHash('md5').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
}
else if (apiConfig.signature.type == 'signed_sha256') { // sha256(key+secret+epoch)
// Add signature parameter
var timeStamp = Math.round(new Date().getTime()/1000);
var sig = hashlib.sha256('' + apiKey + apiSecret + timeStamp + '', { asString: true });
var sig = crypto.createHash('sha256').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
}
}
Expand Down
2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -23,10 +23,8 @@
"dependencies": {
"connect-redis": "1.0.6",
"express": "2.4.3",
"hashlib": "1.0.1",
"jade": "0.13",
"oauth": "0.9.3",
"querystring": "0.0.1",
"redis": "0.6.6"
},
"devDependencies": {},
Expand Down

0 comments on commit ef0abc8

Please sign in to comment.