php-ntlm icon indicating copy to clipboard operation
php-ntlm copied to clipboard

wsdl file fetch with NTLM?

Open benyanke opened this issue 7 years ago • 6 comments

I have read PHP bugs (I wish I could find them again....) that even if the SOAP connection is using a given auth, the WSDL file can not be fetched using the same auth.

Currently, even with your library, I'm having to manually download my WSDL files from my Navision 2013 R2 instance, and point the SoapClient at the filesystem instead of the URL. Is there a workaround for this with your library?

benyanke avatar Oct 02 '17 16:10 benyanke

Came here looking for the same. Sadly it looks like rolling your own is the only way to do it at the moment. I found this, which seems promising.

Morgon avatar Nov 04 '17 14:11 Morgon

@benyanke: I'm having the same issue with NAV 2015. Could you post an example of how you are using local WDSL file?

jasonhildebrand avatar Nov 06 '17 18:11 jasonhildebrand

In essence, I'm just manually storing them in my repository, but my soap client constructor is below. In short, $wsdl contains the filesystem path to the XML file I manually downloaded and stored, and then this getSoapClient function is used in place of the new SoapClient() throughout my code.

<?php
use \jamesiarmes\PhpNtlm\SoapClient;
[...]
class NavBaseModel {
[...]
    public static function getSoapclient(string $pagename) {
        $wsdl = base_path().
        "/resources/nav/wsdlfiles/".config('nav.soapconnection.pages.'.$pagename).
        ".xml";

        return new SoapClient(
            $wsdl,
            array(
                'user' => config('nav.soapconnection.username'),
                'password' => config('nav.soapconnection.password')
            )
        );
    }
[...]
}

benyanke avatar Nov 06 '17 19:11 benyanke

OK, that's what I was trying, but I kept getting PHP Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized when later trying to invoke a soap method.

I am having more success with https://github.com/matejsvajger/ntlm-soap-client, I'm able to make SOAP calls without needing local copies of WSDL files.

jasonhildebrand avatar Nov 06 '17 19:11 jasonhildebrand

I will check that out. That package must properly fetch the WSDL files using NTLM auth.

benyanke avatar Nov 06 '17 19:11 benyanke

Note: I was able to fetch my WSDL file using the following code. Have zero time to implement this in the package and turn this into a PR, but if someone else wants to, here it is:

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $wsdlFile);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
  curl_setopt($ch, CURLOPT_USERPWD, config('nav.soapconnection.username') . ":" . config('nav.soapconnection.password'));

  $wsdlFileContent = curl_exec($ch);
  curl_close($ch);

benyanke avatar Dec 21 '17 16:12 benyanke