PHP SOAP request versus service using SPNEGO

I am trying to access SOAP WebService using PHP. A service is a Windows service that is installed and configured at the client site. The server I'm connecting to is configured to accept two different authentication modes. NTLM or SPNEGO.

I was able to successfully connect to the server without problems when it is configured to use NTLM using the following extension class for SoapClient:

class NTLMSoapClient extends SoapClient {
  function __doRequest($request, $location, $action, $version, $one_way = NULL) {
    $headers = array(
      'Method: POST',
      'Connection: Keep-Alive',
      'User-Agent: PHP-SOAP-CURL',
      'Content-Type: text/xml; charset=utf-8',
      'SOAPAction: "'.$action.'"',
    );
    $this->__last_request_headers = $headers;
    $ch = curl_init($location);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, true );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
    curl_setopt($ch, CURLOPT_USERPWD, "<user>:<password>");
    $response = curl_exec($ch);
    return $response;
  }
  function __getLastRequestHeaders() {
    return implode("\n", $this->__last_request_headers)."\n";
  }
}

However, if I configure the server to use SPNEGO installed in NTLM, it obviously does not work out of the box. I tried to change the following:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

After searching and experimenting, I found people offering to enter a username only without a password:

curl_setopt($ch, CURLOPT_USERPWD, "<user>");

None of this has been done. CURL always responds with HTTP 401 Unauthorized.

phpinfo(); , PHP , CURL SPNEGO.

, , "" SPNEGO , , , SPNEGO- PHP, - , , . .

. , . , SPNEGO , NTLM, .

+4

Source: https://habr.com/ru/post/1529956/


All Articles