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->requestToken() (line 338 of salesforce.inc)

SalesforceException: Error opening socket ssl://login.salesforce.com:443 in Salesforce->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.

  • Have you created an app in Salesforce with URL Callback to your local: https://secure.localhost/ and you're using the right auth keys of that app?
    – kenorb
    Commented Feb 22, 2015 at 16:08
  • Are you trying to use live Salesforce or sandbox? It seems you're trying to use live. So if you're trying to use sandbox, your endpoints are wrong.
    – kenorb
    Commented Feb 22, 2015 at 16:11
  • Do you still get 'HTTP Failure error' in the Status Report, or you're talking about the past?
    – kenorb
    Commented Feb 22, 2015 at 16:12
  • Kenorb, thank you for your replies: Yes I have the right auth keys, I am using a live site in salesforce not sandbox, I created a second connected app for my local site and am using an endpoint that links to my local site. And yes I still get the http failure error in the status report.
    – jtrenton
    Commented Feb 22, 2015 at 19:39
  • Are you using Secure Site or Secure Pages? If yes, disable them to see if that helps. If you go to https://secure.localhost/salesforce/oauth_callback (without any query), what page do you get (or which error)?
    – kenorb
    Commented Feb 22, 2015 at 20:47

1 Answer 1


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->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:

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

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->new(
        ssl_opts => {
                verify_hostname => 1,
                SSL_ca_file => Mozilla::CA::SSL_ca_file()
        }) or die;
my $url = $ARGV[0] || 'https://login.salesforce.com/';
my $res = $ua->get($url);
print $res->code . "\n";


See also:

  • Kenorb, thank you. The php fsockopen does fail, so I will try to determine why. I have gone through the check list you provided and so far nothing is setup that would mess up the connection, or at least not based on the list provided above under "If your curl is connecting fine and you've HTTP Failure error, then:" I will continue to troubleshoot
    – jtrenton
    Commented Feb 24, 2015 at 21:48
  • @jtrenton Added additional info how to debug fsockopen() further more.
    – kenorb
    Commented Feb 24, 2015 at 22:01
  • Here are the errors I get back FYI: Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/XAMPP/xamppfiles/htdocs/mysites/huawei/web/test.php on line 2 Warning: fsockopen(): Failed to enable crypto in /Applications/XAMPP/xamppfiles/htdocs/mysites/huawei/web/test.php on line 2 Warning: fsockopen(): unable to connect to ssl://login.salesforce.com:443 (Unknown error) in /Applications/XAMPP/xamppfiles/htdocs/mysites/huawei/web/test.php on line 2 DOWN:
    – jtrenton
    Commented Feb 24, 2015 at 22:59
  • @jtrenton So it's a problem with the certificate, verify that your system date is correct and try adding insecure to your ~/.curlrc. Otherwise try google it.
    – kenorb
    Commented Feb 24, 2015 at 23:12
  • 1
    Kenorb thank you again for all of your help. I finally managed to fix it by adding the following to my php.ini file openssl.cafile=/usr/local/etc/openssl/cert.pem
    – jtrenton
    Commented Mar 4, 2015 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.