php-ntlm
php-ntlm copied to clipboard
wsdl file fetch with NTLM?
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?
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.
@benyanke: I'm having the same issue with NAV 2015. Could you post an example of how you are using local WDSL file?
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')
)
);
}
[...]
}
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.
I will check that out. That package must properly fetch the WSDL files using NTLM auth.
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);