Added new post method and get method. Deprecated older getProtectedResource method
This commit is contained in:
parent
3564e2e60b
commit
7117b2df3e
24
lib/oauth.js
24
lib/oauth.js
@ -141,7 +141,7 @@ exports.OAuth.prototype._createClient= function( port, hostname, sshEnabled, cre
|
|||||||
return http.createClient(port, hostname, sshEnabled, credentials);
|
return http.createClient(port, hostname, sshEnabled, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, callback ) {
|
exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, callback ) {
|
||||||
var oauthParameters= {
|
var oauthParameters= {
|
||||||
"oauth_timestamp": this._getTimestamp(),
|
"oauth_timestamp": this._getTimestamp(),
|
||||||
"oauth_nonce": this._getNonce(this._nonceSize),
|
"oauth_nonce": this._getNonce(this._nonceSize),
|
||||||
@ -207,7 +207,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
|||||||
headers["Accept"]= "*/*"
|
headers["Accept"]= "*/*"
|
||||||
headers["Connection"]= "close"
|
headers["Connection"]= "close"
|
||||||
headers["User-Agent"]= "Express authentication"
|
headers["User-Agent"]= "Express authentication"
|
||||||
headers["Content-length"]= 0
|
headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii
|
||||||
headers["Content-Type"]= "application/x-www-form-urlencoded"
|
headers["Content-Type"]= "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
var path;
|
var path;
|
||||||
@ -233,7 +233,9 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
|||||||
});
|
});
|
||||||
|
|
||||||
request.socket.addListener("error",callback);
|
request.socket.addListener("error",callback);
|
||||||
|
if( method == "POST" && post_body != null && post_body != "" ) {
|
||||||
|
request.write(post_body);
|
||||||
|
}
|
||||||
request.end();
|
request.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +247,7 @@ exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_s
|
|||||||
extraParams.oauth_verifier= oauth_verifier;
|
extraParams.oauth_verifier= oauth_verifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._performSecureRequest( oauth_token, oauth_token_secret, "GET", this._accessUrl, extraParams, function(error, data, response) {
|
this._performSecureRequest( oauth_token, oauth_token_secret, "GET", this._accessUrl, extraParams, "", function(error, data, response) {
|
||||||
if( error ) callback(error);
|
if( error ) callback(error);
|
||||||
else {
|
else {
|
||||||
var results= querystring.parse( data );
|
var results= querystring.parse( data );
|
||||||
@ -257,8 +259,18 @@ exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_s
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
|
exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
|
||||||
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, callback );
|
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", callback );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, callback) {
|
||||||
|
this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", callback );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, callback) {
|
||||||
|
this._performSecureRequest( oauth_token, oauth_token_secret, "POST", url, null, post_body, callback );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
|
exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
|
||||||
@ -271,7 +283,7 @@ exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
|
|||||||
if( this._authorize_callback ) {
|
if( this._authorize_callback ) {
|
||||||
extraParams["oauth_callback"]= this._authorize_callback;
|
extraParams["oauth_callback"]= this._authorize_callback;
|
||||||
}
|
}
|
||||||
this._performSecureRequest( null, null, "POST", this._requestUrl, extraParams, function(error, data, response) {
|
this._performSecureRequest( null, null, "POST", this._requestUrl, extraParams, "", function(error, data, response) {
|
||||||
if( error ) callback(error);
|
if( error ) callback(error);
|
||||||
else {
|
else {
|
||||||
var results= querystring.parse(data);
|
var results= querystring.parse(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user