NTML Authentication with PHP to Navision SOAP webservice

。_饼干妹妹 提交于 2021-02-10 19:23:11

问题


I'm currently developing a payment gateway that has to send the order to Navision where it will be managed. In the webservice the NTML authentication is enabled so first it is necessary to extend the native class SoapClient. For it I have found enough documentation in the web https://thomas.rabaix.net/articles/using-soap-php-with-ntlm-authentication that allows to extend this native class.

Now the code exposed in that post does not return me the xslm first.

In this case this would be my code

            define("USERPWD", "user:password");

            require_once("NTLMStream.php");
            require_once("NTLMSoapClient.php");

            
            stream_wrapper_unregister('http');
            
            stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
            
            // Initialize Soap Client  
            $url = "http://ipaddress:port/DynamicsNAV1_test/WS/enterprise/Codeunit/SalesEnterprise?WSDL";
            $uri = "urn:microsoft-dynamics-schemas/codeunit/SalesEnterprise";

            $params = [
                'stream_context' => stream_context_create([
                       'ssl' => [
                        'verify_peer'=>false, 
                        'verify_peer_name'=>false, 
                        'allow_self_signed'=>true,
                    ]]),
                'cache_wsdl'=> WSDL_CACHE_NONE,
                'trace' => 1,
            ];

            $client = new NTLMSoapClient($url, $params);
            
            stream_wrapper_restore('http');

As you can see I have dispensed with the classes used by this author to define the credentials.

inally the code returns the following error:

SOAP Fault: (faultcode: WSDL, faultstring: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ipaddress:port/DynamicsNAV1_test/WS/Enterprise/Codeunit/SalesEnterprise?WSDL' : Document is empty).

I will be happy to provide more information if needed. Many thanks in advance!


回答1:


The first 2 responses you get from an NTLM handshake are 401's with no body, the 3rd response if successfully authenticated will contain the 200 and response.

https://techcommunity.microsoft.com/t5/iis-support-blog/windows-authentication-http-request-flow-in-iis/ba-p/324645


Update 30/1/21

Its been a while since ive used Php, but id start with this post that shows how to manually do the NTLM curl from the shell then how to repeat that same command from php curl - curl with ntlm authentication works in command line but not inside php

Also there are some nuggets in the top few answers of this SO search: https://stackoverflow.com/search?q=NTLM+PHP+curl



来源:https://stackoverflow.com/questions/65921846/ntml-authentication-with-php-to-navision-soap-webservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!