Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ object:
```php
use \jamesiarmes\PhpEws\Client;

$ews = new Client($server, $username, $password, $version);
$ews = new Client($server, $username, $password, $version, $client_certificate);
```

The `Client` class takes four parameters for its constructor:
The `Client` class takes five parameters for its constructor:

* `$server`: The url to the exchange server you wish to connect to, without
the protocol. Example: mail.example.com. If you have trouble determining the
Expand All @@ -56,6 +56,8 @@ The `Client` class takes four parameters for its constructor:
* `$version` (optional): The version of the Exchange sever to connect to. Valid
values can be found at `\jamesiarmes\PhpEws\Client::VERSION_*`. Defaults to
Exchange 2007.
* `$client_certicaticate` (optional): The path to the client certificate to use
for authentication. When specified, `$username` and `$password` are ignored.

Once you have your `\jamesiarmes\PhpEws\Client` object, you need to build your
request object. The type of object depends on the operation you are calling. If
Expand Down
59 changes: 50 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class Client
*/
protected $version;

/**
* @var ?string Path to client certificate
*/
protected $client_certificate;

/**
* Constructor for the ExchangeWebServices class
*
Expand All @@ -165,7 +170,8 @@ public function __construct(
$server = null,
$username = null,
$password = null,
$version = self::VERSION_2013
$version = self::VERSION_2013,
$client_certificate = null
) {
// Set the object properties.
$this->setServer($server);
Expand All @@ -189,6 +195,16 @@ public function getClient()
return $this->soap;
}

/**
* Gets the client certificate path (or null if not set)
*
* @return string|null
*/
public function getClientCertificate()
{
return $this->client_certificate;
}

/**
* Sets the cURL options that will be set on the SOAP client.
*
Expand Down Expand Up @@ -280,6 +296,22 @@ public function setVersion($version)
$this->headers = array();
}

/**
* Sets the client certificate. Should be a readable path to a certificate file
*
* @param string $client_certificate
*
* @throws \InvalidArgumentException If the certificate is not readable
*/
public function setClientCertificate($client_certificate)
{
if (!is_readable($client_certificate)) {
throw new \InvalidArgumentException('Client certificate not readable');
}

$this->client_certificate = $client_certificate;
}

/**
* Adds one or more delegates to a principal's mailbox and sets specific
* access permissions.
Expand Down Expand Up @@ -1604,16 +1636,25 @@ public function UploadItems($request)
*/
protected function initializeSoapClient()
{
$options = array(
'location' => 'https://' . $this->server . '/EWS/Exchange.asmx',
'classmap' => $this->classMap(),
'curlopts' => $this->curl_options,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);

//If client certificate is set, add it to the options for usage
//Else, default to login/password
if ($this->client_certificate !== null) {
$options['local_cert'] = $this->client_certificate;
} else {
$options['user'] = $this->username;
$options['password'] = $this->password;
}

$this->soap = new SoapClient(
dirname(__FILE__) . '/assets/services.wsdl',
array(
'user' => $this->username,
'password' => $this->password,
'location' => 'https://' . $this->server . '/EWS/Exchange.asmx',
'classmap' => $this->classMap(),
'curlopts' => $this->curl_options,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
)
$options
);

return $this->soap;
Expand Down