Permalink
Browse files

Merge remote-tracking branch 'dmathieu/fix_http' into not_require_http

Conflicts:
	lib/oauth2.js
  • Loading branch information...
ciaranj committed Apr 24, 2012
2 parents 1359d69 + 3262090 commit 1970e0045efff93867d7e3e9915d95c142549e9c
Showing with 14 additions and 8 deletions.
  1. +14 −8 lib/oauth2.js
View
@@ -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,15 @@ 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 creds = crypto.createCredentials({ });
+ var parsedUrl= URL.parse( url, true );
+ if( parsedUrl.protocol == "https:" && !parsedUrl.port ) {
+ parsedUrl.port= 443;
+ http_library = https;
+ } else {
+ http_library = http;
+ }
+
var realHeaders= {};
if( headers ) {
for(var key in headers) {
@@ -72,7 +78,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 +100,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 +145,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) {

0 comments on commit 1970e00

Please sign in to comment.