Exemplo n.º 1
0
 /**
  * @param string $email
  * @param string $password
  * @param string $username
  */
 protected function newAPI($email, $password, $username = null, $options = [])
 {
     $options = array_replace_recursive(['httpPlayback' => ['mode' => null]], $options);
     $this->httpPlayback = Factory::getInstance($options['httpPlayback']);
     if (!$username) {
         $username = $email;
     }
     $settings = $this->discover($email, $password, $username);
     if (!$settings) {
         throw new AutodiscoverFailed();
     }
     $server = $this->getServerFromResponse($settings);
     $version = $this->getServerVersionFromResponse($settings);
     if (!$server) {
         throw new AutodiscoverFailed();
     }
     $options = [];
     if ($version) {
         $options['version'] = $version;
     }
     return API::withUsernameAndPassword($server, $email, $password, $options);
 }
Exemplo n.º 2
0
 public function testWithCallbackToken()
 {
     //Create our expected item, get our class to build our item, then compare
     $expected = ExchangeWebServices::fromCallbackToken('test.com', 'token', ['version' => ExchangeWebServices::VERSION_2010]);
     $client = API::withCallbackToken('test.com', 'token');
     $actual = $client->getClient();
     $ntlmSoapReflection = new \ReflectionClass(API\NTLMSoapClient::class);
     $reflectedProp = $ntlmSoapReflection->getProperty('auth');
     $reflectedProp->setAccessible(true);
     $this->assertEquals($reflectedProp->getValue($expected->getClient()), $reflectedProp->getValue($actual->getClient()));
 }
Exemplo n.º 3
0
<?php

/**
 * Quick Start
 *
 * This file is an example of how to quickly create a Calendar Item without going through the CalendarAPI, to show
 * that you can create items directly
 */
//Include the API
use garethp\ews\API;
use garethp\ews\API\Enumeration;
//Create and build the client
$api = API::withUsernameAndPassword('server', 'username', 'password');
//Get the folder to save the event to
$folder = $api->getFolderByDistinguishedId('calendar');
//Create our event
$item = array('CalendarItem' => array('Start' => (new \DateTime('8:00 AM'))->format('c'), 'Subject' => 'The Event Subject'));
//Set our options
$options = array('SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE, 'SavedItemFolderId' => array('FolderId' => array('Id' => $folder->getFolderId()->getId())));
//Send the request
$items = $api->createItems($item, $options);
Exemplo n.º 4
0
use garethp\ews\API;
use garethp\ews\API\ExchangeWebServicesAuth;
//In order to authenticate your application with Office 365 using OAuth 2.0 instead of usernames and passwords, you
//need to do some extra work to handle the actual authentication. The first is to register your application in Azure AD
//which can be done by following this: https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually
//Once you've done that, you should have the following: A Redirect URI, a token and authorization endpoint (can be found
//by clicking on the "View Endpoints" button when managing your application, a Client ID and a Client Secret. You should
//also have added "Office 365 Exchange Online" as an application that you have permission to use, with the Delegate
//Permission of "Access mailboxes as the signed-in user via Exchange Web Services" ticked.
$tokenEndpoint = null;
$authorizationEndpoint = null;
$clientId = null;
$clientSecret = null;
$redirectUri = null;
$resource = 'https://outlook.office365.com';
//The first step is to get your authorization code. It's a one time use code that needs to be granted by the user. You
//should have your own way to get it, but just for the sake of example I'm going to show you a way to do that
if (!$_SESSION['token'] && !isset($_GET)) {
    $redirect = $authorizationEndpoint . '?response_type=code' . '&client_id=' . urlencode($clientId) . '&redirect_uri=' . urlencode($redirectUri) . '&resource=' . urlencode($resource) . '&scope=' . urlencode('full_access_as_user');
    header("Location: {$redirect}");
    exit;
} elseif (isset($_GET['code'])) {
    $code = $_GET['code'];
    $token = ExchangeWebServicesAuth::getTokenFromAuthorizationCode($clientId, $clientSecret, $code, $redirectUri, $tokenEndpoint);
    $_SESSION['token'] = $token;
}
//Once you have your token you can just create your API as easily as before, but with the token instead of with a
//username and a password
$token = $_SESSION['token'];
$api = API::withCallbackToken('outlook.office365.com', $token);
Exemplo n.º 5
0
<?php

use garethp\ews\API\Type\ConnectingSIDType;
use garethp\ews\API\Type\ExchangeImpersonation;
//Impersonate an email address
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => '*****@*****.**']);
//Build your own impersonation
$connectingSID = new ConnectingSIDType();
$connectingSID->setPrincipalName('Some Name');
$connectingSID->setPrimarySmtpAddress('*****@*****.**');
$impersonation = new ExchangeImpersonation();
$impersonation->setConnectingSID($connectingSID);
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => $impersonation]);
Exemplo n.º 6
0
<?php

include "vendor/autoload.php";
use garethp\ews\API\ExchangeAutodiscover;
use garethp\ews\API\Exception\AutodiscoverFailed;
use garethp\ews\API;
try {
    //API will now be an instance of \garethp\ews\API;
    $api = ExchangeAutodiscover::getAPI('*****@*****.**', 'password');
    $timezoneList = $api->getServerTimezones();
    //You should never run the Autodiscover more than once. It can make between 1 and 5 calls before giving up, or
    //before finding your server, depending on how many different attempts it needs to make. For this reason, you should
    //only ever do it once to find out where your server is located and what version it's running, and then hard code
    //that or store it in a database, or anything other than running Autodiscover again
    $server = $api->getClient()->getServer();
    $version = $api->getClient()->getVersion();
    $api = API::withUsernameAndPassword($server, '*****@*****.**', 'password', ['version' => $version]);
} catch (AutodiscoverFailed $exception) {
    //Autodiscover failed
}
Exemplo n.º 7
0
 /**
  * Get a list of changes on the calendar items
  *
  * @param null $syncState
  * @param array $options
  * @return API\Message\SyncFolderItemsResponseMessageType
  */
 public function listChanges($syncState = null, $options = array())
 {
     return parent::listItemChanges($this->getFolderId(), $syncState, $options);
 }
Exemplo n.º 8
0
<?php

require_once "vendor/autoload.php";
use garethp\ews\API\Type;
use garethp\ews\API\Type\CalendarItem;
use garethp\ews\Caster;
use garethp\ews\Test\API\TypeTest;
use garethp\ews\CalendarAPI;
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['primarySmtpEmailAddress' => '*****@*****.**']);
$api->getFolderByDistinguishedId('inbox');