Updated the Oauth2 code to work with the new https api
This commit is contained in:
parent
5041ca168a
commit
349d258b1f
@ -1,10 +1,8 @@
|
||||
var querystring= require('querystring'),
|
||||
crypto= require('crypto'),
|
||||
http= require('http'),
|
||||
https= require('https'),
|
||||
URL= require('url');
|
||||
|
||||
var sys= require('sys');
|
||||
|
||||
exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, accessTokenPath) {
|
||||
this._clientId= clientId;
|
||||
this._clientSecret= clientSecret;
|
||||
@ -29,7 +27,6 @@ exports.OAuth2.prototype._request= function(method, url, headers, access_token,
|
||||
var creds = crypto.createCredentials({ });
|
||||
var parsedUrl= URL.parse( url, true );
|
||||
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) parsedUrl.port= 443;
|
||||
var httpClient = http.createClient(parsedUrl.port, parsedUrl.hostname, true, creds);
|
||||
|
||||
var realHeaders= {};
|
||||
if( headers ) {
|
||||
@ -46,17 +43,17 @@ exports.OAuth2.prototype._request= function(method, url, headers, access_token,
|
||||
parsedUrl.query["access_token"]= access_token;
|
||||
}
|
||||
|
||||
var request = httpClient.request(method, parsedUrl.pathname + "?" + querystring.stringify(parsedUrl.query), realHeaders );
|
||||
|
||||
httpClient.addListener("secure", function () {
|
||||
/* // disable verification for now.
|
||||
|
||||
var verified = httpClient.verifyPeer();
|
||||
if(!verified) this.end(); */
|
||||
});
|
||||
|
||||
var result= "";
|
||||
request.addListener('response', function (response) {
|
||||
|
||||
var options = {
|
||||
host:parsedUrl.hostname,
|
||||
port: parsedUrl.port,
|
||||
path: parsedUrl.pathname + "?" + querystring.stringify(parsedUrl.query),
|
||||
method: method,
|
||||
headers: realHeaders
|
||||
};
|
||||
|
||||
request = https.request(options, function (response) {
|
||||
response.addListener("data", function (chunk) {
|
||||
result+= chunk
|
||||
});
|
||||
@ -69,6 +66,10 @@ var verified = httpClient.verifyPeer();
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', function(e) {
|
||||
callback(e);
|
||||
});
|
||||
|
||||
request.end();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user