Skip to content

Commit

Permalink
Fixed HTTPS POST Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DveMac committed Feb 19, 2011
1 parent dd6736c commit 9e126ec
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/connect-rpx.js
@@ -1,12 +1,12 @@
var sys = require('sys');
var fs = require('fs');
var http = require('http');
var https = require('https');
var qs = require('querystring');

// Connect Middleware for integrating RPX Now into your application
var RPX_HOST = 'rpxnow.com';
var RPX_LOGIN_ROOT = "/api/v2/auth_info";
var RPX_LOGIN_URL = "https://rpxnow.com/api/v2/auth_info";
//var RPX_LOGIN_URL = "/api/v2/auth_info";

var options = {
callback_path : '/login_completed',
Expand Down Expand Up @@ -64,21 +64,20 @@ function postWithCredentials( token, req, res, next ) {
'Content-Type' : 'application/x-www-form-urlencoded',
'Content-Length' : toPost.length };
var rpxResponseBody = '';
var postRequest = http.createClient( 443, RPX_HOST, true ).request( 'POST', RPX_LOGIN_ROOT, toPostHeader );
postRequest.write( toPost, 'utf8' );
postRequest.on( 'response', function(rpxResponse) {
rpxResponse.on( 'data', function( data ) {
// sys.puts( "Chunk: " + data );
var postRequest = https.request( { port:443, host: RPX_HOST, path: RPX_LOGIN_ROOT, method: 'POST', headers: toPostHeader }, function(rpxResponse) {
rpxResponse.on( 'data', function( data ) {
rpxResponseBody += data;
} );
rpxResponse.on( 'end', function() { onCredentialsReceived( rpxResponseBody, req, res, next ) } );
rpxResponse.on( 'error', onError );
});
postRequest.end();
});

rpxResponse.on( 'end', function() { onCredentialsReceived( rpxResponseBody, req, res, next ) } );
rpxResponse.on( 'error', onError );
});
postRequest.on( 'error', onError );
postRequest.end(toPost, 'utf8' );
}

function onError(response) {
sys.puts( "Something bad happened" );
sys.puts( "Something bad happened: " + response );
}

function onCredentialsReceived(data, req, res, next) {
Expand All @@ -88,6 +87,7 @@ function onCredentialsReceived(data, req, res, next) {
json = JSON.parse( data );
}
catch( e ) {
sys.puts(data);
sys.puts( "E: " + sys.inspect( e ) );
}
}
Expand Down

0 comments on commit 9e126ec

Please sign in to comment.