From 1b4624cacdde42292e6baeedc5992aac7f1d32fe Mon Sep 17 00:00:00 2001 From: Raoul Millais Date: Tue, 16 Aug 2011 13:26:49 +0100 Subject: [PATCH] Added support for GET when requesting request tokens --- lib/oauth.js | 7 ++++++- tests/oauth.js | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/oauth.js b/lib/oauth.js index d231b13..6f24718 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -460,16 +460,21 @@ exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, pos } exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) { + var httpMethod; if( typeof extraParams == "function" ){ callback = extraParams; extraParams = {}; } + if( typeof callback == "string"){ + httpMethod = callback; + } + // Callbacks are 1.0A related if( this._authorize_callback ) { extraParams["oauth_callback"]= this._authorize_callback; } - this._performSecureRequest( null, null, "POST", this._requestUrl, extraParams, null, null, function(error, data, response) { + this._performSecureRequest( null, null, httpMethod || "POST", this._requestUrl, extraParams, null, null, function(error, data, response) { if( error ) callback(error); else { var results= querystring.parse(data); diff --git a/tests/oauth.js b/tests/oauth.js index 0609df6..2988951 100644 --- a/tests/oauth.js +++ b/tests/oauth.js @@ -133,6 +133,19 @@ vows.describe('OAuth').addBatch({ assert.equal( oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret"), "http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D"); } }, + 'When getting a request token': { + topic: function() { + var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1"); + oa._getTimestamp= function(){ return "1272399856"; } + oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; } + oa._performSecureRequest= function(){ return this.requestArguments = arguments; } + return oa; + }, + 'Use the provided HTTP method': function(oa) { + oa.getOAuthRequestToken(function() {}, "GET"); + assert.equal(oa.requestArguments[2], "GET"); + } + }, 'When get authorization header' : { topic: function() { var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");