Skip to content
This repository

OAuth: set self.method to GET if it's not set #127

wants to merge 1 commit into from

3 participants

Chris O'Hara Mikeal Rogers Chris Verwymeren
Chris O'Hara

Line 221 uses self.method before it might be set (line 328)

Chris O'Hara

Also, some OAuth providers seem to complain if the URL is encoded with encodeURIComponent rather than rfc3986, e.g. LinkedIn field selectors. Swapping the two on this line makes it work

Chris O'Hara

One more thing, the rfc3986 function is only replacing the first occurrence of each special char, fix:

  return encodeURIComponent(str)
Mikeal Rogers

start() should be called before the OAuth code is ever called. Setting to GET needs to happen in start() so that we can keep an explicit method set even when a ServerRequest object is piped to it.

Mikeal Rogers

hrm..... tried to move the OAuth code in to start() and one of the tests now fails :(

don't have time to run this down today.

Chris Verwymeren

This issue appears to cause problems when using methods in the Twitter REST API that require GET.

For example:

var requestOptions = {
    url: '',
    oauth: {
        consumer_key: 'CONSUMER_KEY',
        consumer_secret: 'CONSUMER_SECRET',
        token: 'TOKEN',
        token_secret: 'TOKEN_SECRET'

request.get(requestOptions, function (e, r, b) {
    if (b) console.log(b);

Results in:

{"error":"Could not authenticate with OAuth.","request":"\/1\/statuses\/home_timeline.json"}

Setting GET before start() is called corrects this issue. As a workaround, is it possible to manually set GET?

Mikeal Rogers

this pull request no longer merges cleanly. please get it up to date if this is still an issue.

Chris Verwymeren cvee referenced this pull request

Fix for Issue #127 #157

Mikeal Rogers mikeal closed this pull request from a commit
Mikeal Rogers fixes #127 ee53386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 06, 2011
Chris O'Hara chriso Set self.method to GET if it's not set a08e404
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. +1 1  main.js
2  main.js
@@ -128,6 +128,7 @@ Request.prototype.request = function () {
128 128 self.redirects = self.redirects || []
129 129
130 130 self.headers = self.headers ? copy(self.headers) : {}
  131 + self.method = self.method || 'GET'
131 132
132 133 var setHost = false
133 134 if (! {
@@ -325,7 +326,6 @@ Request.prototype.request = function () {
325 326
326 327 self.start = function () {
327 328 self._started = true
328   - self.method = self.method || 'GET'
329 329
330 330 self.req = self.httpModule.request(self, function (response) {
331 331 self.response = response

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.