Permalink
Browse files

Fixed HTTPS POST Issue

  • Loading branch information...
1 parent dd6736c commit 9e126ecb4fbe922e2292bc3d246aa7b30b740b0c @DveMac DveMac committed Feb 19, 2011
Showing with 13 additions and 13 deletions.
  1. +13 −13 lib/connect-rpx.js
View
@@ -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',
@@ -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) {
@@ -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 ) );
}
}

0 comments on commit 9e126ec

Please sign in to comment.