How to fix SalesForce authentication errors on localhost? I am fairly new to developing with Drupal, and new to this forum, so any help would be greatly appreciated.
While trying to authorize SalesForce with a local install I get the following two errors with when going to the oauth_callback.
Note: I have not included the entire path to save space but the reference points are accurate for the doc and line the error references.

Notice: Undefined property: stdClass::$data in Salesforce-&gt;requestToken() (line 338 of salesforce.inc)
SalesforceException: Error opening socket ssl://login.salesforce.com:443 in Salesforce-&gt;requestToken() (line 342 of salesforce.inc)

Local Environment: Mac OS Mavericks with XAMPP 5.6.3, SSL enabled on port 443 in httpd-vhosts.conf with certs created using OpenSSL.
Extension: php_openssl.dll uncommented in php.ini
Also to note the Drupal install was pulled from a live site that has SF module enabled and working.
I created a new connected app with the proper oauth_callback to the local site which is https://secure.localhost/salesforce/oauth_callback
I have both HTTPS and HTTP enabled, I have noticed that in the Status Report when using HTTPS I do get a HTTP Failure error in the status report.
The request url from salesforce is passing a code EX: https://secure.localhost/salesforce/oauth_callback?code=aPrxMZkm7lCkgfR3...
With a Status code of 500 Service unavailable.
I have looked all over online and on this site, and can't seem to find anything that works. I have tried a few patches to the common.inc file, but none of them seemed to work.
Like I said any help would be greatly appreciated, I am just not sure if it is Drupal, Salesforce, or my local setup.
In general, to make SalesForce authentication to work on localhost, you need to:


Create an app in Salesforce with URL Callback to your local (https://localhost/salesforce/oauth_callback) with appropriate permissions.


  In Salesforce go to Your Name > Setup > Create > Apps then create a new Connected App. (Depending on your Salesforce instance, you may need to go to Your Name > Setup > Develop > Remote Access.)

Your site needs to be SSL enabled to authorize the remote application using OAUTH.
If using the SOAP API, PHP must be compiled with SOAP web services and OpenSSL support.
Use the right auth key and secret to Authorize your app (Configuration » Salesforce).
Make sure you're connecting to the right endpoints (live or sandbox).
For more help, check Help » Salesforce API in Drupal, or SalesForce documentation.
Add $conf['https'] = TRUE; to your setting file.


The error in Salesforce-&gt;requestToken() indicates that there is a problem exchanging an authorization code for an access token.

Further more, the error:


  Error opening socket ssl://login.salesforce.com:443 in Salesforce->requestToken()


indicates the problem connecting to Salesforce endpoint it-self (check requestToken() in includes/salesforce.inc for more details).

To diagnose the problem, please check Reports » Status report if you've got HTTP Failure error and that your localhost can connect to Salesforce end point via curl:

$ curl login.salesforce.com:443


If your curl is connecting fine and you've still HTTP Failure error in your Status report, then try to:


Temporary disable Secure Site or Secure Pages modules if present.
Make sure you've firewall (e.g. iptables) and antivirus is switched off (for testing purposes).
Make sure you're not behind the proxy.
Make sure you're not running LAMP in a chroot/jail/VM environment.
Make sure you some network functions aren't disabled PHP functions (e.g. stream_socket_client).
Make sure your PHP is not in Safe mode (safe_mode = On) by:

php -r "var_dump(ini_get('safe_mode'));"

Double check your /etc/hosts or ~/.curlrc doesn't have anything suspicious (you can add insecure to your .curlrc for testing purposes).
Check is there is no any problem with certificates (e.g. your system date is incorrect, you added the certificate and your PHP openssl sees your certificates correctly).

In PHP 5.6 you can specify openssl.cafile and openssl.capath,

e.g. openssl.cafile=/usr/local/etc/openssl/cert.pem


If none of above work, please check below simple PHP script which can check if your PHP can connect to external host:

&lt;?php
fsockopen('ssl://login.salesforce.com',443,$errno,$errstr) ? print("UP") : print("DOWN:".$errstr);
?&gt;


Save it to the file (test.php) and place it inside your web root and open via web browser.

If it fails, it's either problem with your PHP configuration or your network. You can debug it further more by using system call tracer (debugger) as below (install it if required):

$ strace -f -e network php test.php # For Linux
$ truss -f php test.php # For BSD
$ sudo dtruss php test.php # For OSX
# For Windows, you may look for StraceNT.


Then you've to analyse the log for any issues.

Or the following perl script:

use strict;
use warnings;

use LWP::UserAgent;
use Mozilla::CA;
my $ua = LWP::UserAgent-&gt;new(
        ssl_opts =&gt; {
                verify_hostname =&gt; 1,
                SSL_ca_file =&gt; Mozilla::CA::SSL_ca_file()
        }) or die;
my $url = $ARGV[0] || 'https://login.salesforce.com/';
my $res = $ua-&gt;get($url);
print $res-&gt;code . "\n";

exit;


See also:


Using cURL in PHP to access HTTPS (SSL/TLS) protected sites.
SSL Certificate Verification
Using Curl to login to Salesforce API at Salesforce Developers
token failed with status 0! at Salesforce Developers
How to fix Curl Error Ssl Certificate Problem Verify That The Ca Error?