Merge branch 'not_require_http' into merge_mayhem

This commit is contained in:
ciaranj 2012-04-24 21:12:02 +01:00
commit 5d0072d759
2 changed files with 19 additions and 9 deletions

View File

@ -10,7 +10,7 @@ Also provides rudimentary OAuth2 support, tested against facebook connect and gi
Change History
==============
* 0.10.0 - OAuth2: Pass back any extra response data for calls to getOAuthAccessToken (Thanks to Tang Bo Hao)
* 0.10.0 - OAuth2: Pass back any extra response data for calls to getOAuthAccessToken (Thanks to Tang Bo Hao) OAuth2: Don't force a https request if given a http url (Thanks to Damien Mathieu)
* 0.9.6 - Support for 302 redirects on OAuth2 (Thanks Patrick Negri). Some code tidying. ( Thanks to Raoul Millais )
* 0.9.5 - Allow usage of HTTP verbs other than GET for retrieving the access and request tokens (OAuth1) (Thanks to Raoul Millais)
* 0.9.4 - Support for OAuth providers that drop connections (don't send response lengths? [Google]) And change OAuth2 getOAuthAccessToken to POST rather than GET ( Possible Breaking change!!! ... re-tested against Google, Github, Facebook, FourSquare and Janrain and seems ok .. is closer to the spec (v20) )
@ -41,3 +41,4 @@ Contributors
* Raoul Millais
* Patrick Negri - http://github.com/pnegri
* Tang Bo Hao - http://github.com/btspoony
* Damien Mathieu - http://42.dmathieu.com

View File

@ -1,12 +1,13 @@
var querystring= require('querystring'),
crypto= require('crypto'),
https= require('https'),
http= require('http'),
URL= require('url'),
OAuthUtils= require('./_utils');
exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, accessTokenPath) {
this._clientId= clientId;
this._clientSecret= clientSecret;
this._clientSecret= clientSecret;
this._baseSite= baseSite;
this._authorizeUrl= authorizePath || "/oauth/authorize";
this._accessTokenUrl= accessTokenPath || "/oauth/access_token";
@ -28,10 +29,18 @@ exports.OAuth2.prototype._getAccessTokenUrl= function() {
exports.OAuth2.prototype._request= function(method, url, headers, post_body, access_token, callback) {
var creds = crypto.createCredentials({ });
var parsedUrl= URL.parse( url, true );
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) parsedUrl.port= 443;
var http_library= https;
var creds = crypto.createCredentials({ });
var parsedUrl= URL.parse( url, true );
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) {
parsedUrl.port= 443;
}
// As this is OAUth2, we *assume* https unless told explicitly otherwise.
if( parsedUrl.protocol != "https:" ) {
http_library= http;
}
var realHeaders= {};
if( headers ) {
for(var key in headers) {
@ -72,7 +81,7 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
}
}
var request = https.request(options, function (response) {
var request = http_library.request(options, function (response) {
response.on("data", function (chunk) {
result+= chunk
});
@ -94,7 +103,7 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
request.write(post_body);
}
request.end();
}
}
exports.OAuth2.prototype.getAuthorizeUrl= function( params ) {
@ -139,7 +148,7 @@ exports.OAuth2.prototype.getOAuthAccessToken= function(code, params, callback) {
callback(null, access_token, refresh_token, results); // callback results =-=
}
});
}
}
// Deprecated
exports.OAuth2.prototype.getProtectedResource= function(url, access_token, callback) {