Skip to content

Commit

Permalink
Refresh oauth_nonce only when redirecting to the same hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed May 14, 2015
1 parent 12ff833 commit 195d4c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion request.js
Expand Up @@ -628,7 +628,7 @@ Request.prototype.init = function (options) {

if (options.oauth) {
self.oauth(options.oauth)
} else if (self._oauth.params) {
} else if (self._oauth.params && self.hasHeader('authorization')) {
self.oauth(self._oauth.params)
}

Expand Down
32 changes: 32 additions & 0 deletions tests/test-oauth.js
Expand Up @@ -620,3 +620,35 @@ tape('refresh oauth_nonce on redirect', function(t) {
})
})
})

tape('no credentials on external redirect', function(t) {
var s1 = http.createServer(function (req, res) {
res.writeHead(302, {location:'http://127.0.0.1:6768'})
res.end()
})
var s2 = http.createServer(function (req, res) {
res.writeHead(200, {'content-type':'text/plain'})
res.end()
})
s1.listen(6767, function () {
s2.listen(6768, function () {
request.get(
{ url: 'http://localhost:6767'
, oauth:
{ consumer_key: 'consumer_key'
, consumer_secret: 'consumer_secret'
, token: 'token'
, token_secret: 'token_secret'
}
}, function (err, res, body) {
t.equal(err, null)
t.equal(res.request.headers.Authorization, undefined)
s1.close(function () {
s2.close(function () {
t.end()
})
})
})
})
})
})

0 comments on commit 195d4c0

Please sign in to comment.