Skip to content

Commit

Permalink
Merge branch 'add_https_support' into peaceworks-mods
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhildebrand committed Dec 20, 2017
2 parents 0208ed2 + fac047c commit 3ab7b5e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All Notable changes to `ntlm-soap-client` will be documented in this file.

## Unreleased

### Added
- added support for HTTPS streams
- added support for passing arbitrary CURL options


## Version 1.1.0 - 2016-11-16

### Added
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ $ composer require matejsvajger/ntlm-soap-client
## Usage

``` php
$url = 'URL_TO_WEBSERVICE';
$config = new matejsvajger/NTLMSoap/Common/NTLMConfig([
$url = 'URL_TO_WEBSERVICE_WSDL'; // http and https are both supported
$config = new matejsvajger\NTLMSoap\Common\NTLMConfig([
'domain' => 'domain',
'username' => 'username',
'password' => 'password'
'password' => 'password',

// optionally pass curl options to be used
// for example, to disable SSL verification when using self-signed certs
'curlOptions' => array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
)
]);

$client = new matejsvajger/NTLMSoap/Client($url, $config);
$client = new matejsvajger\NTLMSoap\Client($url, $config);

$response = $client->ReadMultiple(['filter'=>[], 'setSize'=>1]);

Expand Down
8 changes: 8 additions & 0 deletions src/NTLMSoap/Common/NTLMConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ protected function assertParametersAreValid(array $parameters)
}
}

public static function getCurlOptions()
{
if (isset($GLOBALS['NTLMClientCurlOptions'])) {
return $GLOBALS['NTLMClientCurlOptions'];
}
return array();
}

public function __set($param, $value)
{
$this->parameters[$param] = $value;
Expand Down
9 changes: 5 additions & 4 deletions src/NTLMSoap/Model/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ public function __construct($wdsl, NTLMConfig $config = null, $options = [])
$this->wdsl = $wdsl;
$this->config = $config;

$wrapperExists = in_array("http", stream_get_wrappers());
$scheme = parse_url($wdsl, PHP_URL_SCHEME); // we expect 'http' or 'https'
$wrapperExists = in_array($scheme, stream_get_wrappers());
if ($wrapperExists) {
stream_wrapper_unregister('http');
stream_wrapper_unregister($scheme);
}

//- Replace HTTP Stream with NTLMStream for authentication headers.
stream_wrapper_register('http', 'matejsvajger\NTLMSoap\Model\Stream\NTLMStream');
stream_wrapper_register($scheme, 'matejsvajger\NTLMSoap\Model\Stream\NTLMStream');

parent::__construct($wdsl, $options);

//- Restore http wrapper - further requests handled via cURL
if ($wrapperExists) {
stream_wrapper_restore('http');
stream_wrapper_restore($scheme);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/NTLMSoap/Model/Stream/NTLMStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ private function createBuffer($path)
curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($this->ch, CURLOPT_USERPWD, $auth);
foreach (NTLMConfig::getCurlOptions() as $option => $value) {
curl_setopt($this->ch, $option, $value);
}
$this->buffer = curl_exec($this->ch);
$this->pos = 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/NTLMSoap/Model/Traits/NTLMRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function __doRequest($request, $location, $action, $version, $one_way = n
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $auth);

foreach (NTLMConfig::getCurlOptions() as $option => $value) {
curl_setopt($ch, $option, $value);
}
$response = curl_exec($ch);

return $response;
Expand Down

0 comments on commit 3ab7b5e

Please sign in to comment.