Skip to content

Commit

Permalink
Merge pull request #4 from MathieuLescure/master
Browse files Browse the repository at this point in the history
Fix a bug when using GET instead of POST
  • Loading branch information
drudge committed Aug 31, 2014
2 parents eea5304 + 4f1e7b8 commit cbd4eaf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/passport-twitter-token/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ TwitterTokenStrategy.prototype.authenticate = function(req, options) {
}

var self = this;
var token = req.body.oauth_token || req.query.oauth_token;
var tokenSecret = req.body.oauth_token_secret || req.query.oauth_token_secret;
var userId = req.body.user_id || req.query.user_id;
var token = lookup(req.body, 'oauth_token') || lookup(req.query, 'oauth_token');
var tokenSecret = lookup(req.body, 'oauth_token_secret') || lookup(req.query, 'oauth_token_secret');
var userId = lookup(req.body, 'user_id') || lookup(req.query, 'user_id');
var params = { user_id: userId };

self._loadUserProfile(token, tokenSecret, params, function(err, profile) {
Expand Down Expand Up @@ -107,6 +107,18 @@ TwitterTokenStrategy.prototype.authenticate = function(req, options) {
}
}
});

function lookup(obj, field) {
if (!obj) { return null; }
var chain = field.split(']').join('').split('[');
for (var i = 0, len = chain.length; i < len; i++) {
var prop = obj[chain[i]];
if (typeof(prop) === 'undefined') { return null; }
if (typeof(prop) !== 'object') { return prop; }
obj = prop;
}
return null;
}
}

/**
Expand Down

0 comments on commit cbd4eaf

Please sign in to comment.