Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem connecting to a SOAP API in password protected directory

I am trying to access a Magento API, using SOAP. the code I have works fine normally, however the client wishes to password protect the Magento main folder. Doing so breaks access to the API and causes an error.

The documentation suggests this isnt a problem and you can just specify the username/password, however this does not work.

I am using PHP and IIS, with the password protection set up via Plesk 10. Does this use Basic HTTP authentication or something else?

My access code is:

$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) 
                    ); 
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
                    array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) ); 

The error I get is:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20

The line referred to is the $client->login command.

Any suggestions?

like image 966
Gavin Coates Avatar asked Dec 10 '22 06:12

Gavin Coates


1 Answers

I've faced a similiar problem long time ago.

In my case, I didn't immediately realize that I need to use .htaccess credentials while creating the SoapClient instance, but pass SOAP API credentials to the login method.

I was passing the SOAP API credentials all over and got a similiar error like you do.

Here's what worked for me (1.3.x version, though. Still works for me as of today):

$cProxy = new SoapClient(
    URL . 'index.php/api/soap/?wsdl',
    array(
        'login' => HTACCESS_USER,
        'password' => HTACCESS_PASS
    )
);
$rSessionId = $cProxy->login(
    SOAP_USER,
    SOAP_PASS
);

Just to play save, that you are didn't got trapped by a typo: you pass $GLOABLS["magento_api_password"] as 2nd param to the login method, which should be $GLOBALS["magento_api_password"].

Finally, you're passing a 3rd argument to the login method which I believe is obsolete, since afaik it's defined to have two params only:

<message name="login">
    <part name="username" type="xsd:string" />
    <part name="apiKey" type="xsd:string" />
</message>
like image 113
Jürgen Thelen Avatar answered Jan 11 '23 13:01

Jürgen Thelen