diff --git a/examples/GraphConsole/ClientApp.php b/examples/GraphConsole/ClientApp.php deleted file mode 100644 index 798494f4..00000000 --- a/examples/GraphConsole/ClientApp.php +++ /dev/null @@ -1,35 +0,0 @@ -acquireTokenForUserCredential("https://graph.microsoft.com",$AppSettings['ClientId'],new UserCredentials($Settings['UserName'],$Settings['Password'])); - //$authCtx->acquireTokenForClientCredential("https://graph.microsoft.com",new ClientCredential($AppSettings['ClientId'],$AppSettings['ClientSecret'])); - $serviceRootUrl = "https://graph.windows.net/" . $AppSettings['TenantName'] . "/"; - $client = new ActiveDirectoryClient($serviceRootUrl,$authCtx); - //$tenantDetails = $client->getTenantDetails(); - //$client->load($tenantDetails); - //$client->executeQuery(); - - - $request = new RequestOptions("https://graph.windows.net/media18.onmicrosoft.com/users"); - $request->Url .= "?api-version=1.0"; - $response = $client->executeQueryDirect($request); - print "Ok"; -} -catch (Exception $e) { - echo 'Error: ', $e->getMessage(), "\n"; -} \ No newline at end of file diff --git a/examples/GraphConsole/ConsoleTasks.php b/examples/GraphConsole/ConsoleTasks.php new file mode 100644 index 00000000..9619d26e --- /dev/null +++ b/examples/GraphConsole/ConsoleTasks.php @@ -0,0 +1,54 @@ +getMessage(), "\n"; +} + + +function getDriveInfo(GraphServiceClient $client){ + $drive = $client->getMe()->getDrive(); + $client->load($drive); + $client->executeQuery(); + print $drive->getProperty("webUrl"); +} + + +function downloadPhoto(GraphServiceClient $client,$targetFilePath){ + $fp = fopen($targetFilePath, 'w+'); + //$url = $client->getServiceRootUrl() . "me/photo\$value"; + $url = $client->getServiceRootUrl() . "me/photo"; + $options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url); + //$options->StreamHandle = $fp; + $content = $client->executeQueryDirect($options); + fclose($fp); +} + + +function getAuthenticatedClient(){ + global $AppSettings; + global $Settings; + $resource = "https://graph.microsoft.com"; + $authorityUrl = OAuthTokenProvider::$AuthorityUrl . $AppSettings['TenantName']; + $authCtx = new AuthenticationContext($authorityUrl); + $authCtx->acquireTokenForUserCredential($resource,$AppSettings['ClientId'],new UserCredentials($Settings['UserName'],$Settings['Password'])); + $client = new GraphServiceClient($authCtx); + return $client; +} + + + diff --git a/examples/GraphExplorer/ProcessQuery.php b/examples/GraphExplorer/ProcessQuery.php index dee52077..cfe8e427 100644 --- a/examples/GraphExplorer/ProcessQuery.php +++ b/examples/GraphExplorer/ProcessQuery.php @@ -1,5 +1,5 @@ Url .= "?api-version=1.0"; $request->Url .= "?api-version=beta"; - $response = $client->executeQueryDirect($request); + try { + $response = $client->executeQueryDirect($request); + } catch (Exception $e) { + } echo $response; } else diff --git a/examples/Settings.php b/examples/Settings.php index 941c075c..44459806 100644 --- a/examples/Settings.php +++ b/examples/Settings.php @@ -1,16 +1,16 @@ "https://mediadev20.sharepoint.com/sites/contoso", - 'OneDriveUrl' => "https://mediadev20-my.SharePoint.com", + 'Url' => "https://mediadev23.sharepoint.com", + 'OneDriveUrl' => "https://mediadev23-my.SharePoint.com", 'Password' => "P@ssw0rd", - 'UserName' => "mattim@mediadev20.onmicrosoft.com" + 'UserName' => "mattim@mediadev23.onmicrosoft.com" ); $AppSettings = array( - 'TenantName' => "mediadev20.onmicrosoft.com", - 'ClientId' => "13d4cd98-1761-4416-b01c-a641c08d0737", - 'ClientSecret' => "oYM9GUiE4uejyaQ0GuuHj7U", + 'TenantName' => "mediadev23.onmicrosoft.com", + 'ClientId' => "d426369e-c84b-47db-b6b1-b9c824ac2ea2", + 'ClientSecret' => "wrizJBW41]|=@govNEDR059", 'Title' => "Office365 Graph explorer", 'RedirectUrl' => "http://localhost:8078/GraphExplorer/SignIn.php" ); diff --git a/examples/SharePoint/file_examples.php b/examples/SharePoint/file_examples.php index c8ed0bd0..c4eb6edd 100644 --- a/examples/SharePoint/file_examples.php +++ b/examples/SharePoint/file_examples.php @@ -17,7 +17,14 @@ $targetLibraryTitle = "Documents"; $targetFolderUrl = "/sites/contoso/Documents/Archive/2017/08"; - $list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary); + //$list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary); + + + $fileUrl = "/sites/contoso/Shared Documents/Guide #123.docx"; + $file = $ctx->getWeb()->getFileByServerRelativeUrl($fileUrl); + $ctx->load($file); + $ctx->executeQuery(); + $folderUrl = "Shared Documents"; $fileUrl = "Guide #123.docx"; @@ -58,6 +65,7 @@ function createSubFolder(ClientContext $ctx,$parentFolderUrl,$folderName){ $ctx->load($files); $ctx->executeQuery(); //print files info + /* @var $file \Office365\PHP\Client\SharePoint\File */ foreach ($files->getData() as $file) { print "File name: '{$file->getProperty("ServerRelativeUrl")}'\r\n"; } diff --git a/examples/SharePoint/list_examples.php b/examples/SharePoint/list_examples.php index ca11fd69..70e9e94f 100644 --- a/examples/SharePoint/list_examples.php +++ b/examples/SharePoint/list_examples.php @@ -15,6 +15,14 @@ $ctx = new ClientContext($Settings['Url'],$authCtx); + $listTitle = 'Archive 2017'; + //$listTitle = 'Archive%202017'; + $list = $ctx->getWeb()->getLists()->getByTitle($listTitle); + $ctx->load($list); + $ctx->executeQuery(); + + echo $list->getProperty('Title'); + $listTitle = "Orders_" . rand(1,1000); //$listTitle = "Tasks" ; diff --git a/examples/SharePoint/web_examples.php b/examples/SharePoint/web_examples.php index 8346bb79..dd865cd5 100644 --- a/examples/SharePoint/web_examples.php +++ b/examples/SharePoint/web_examples.php @@ -10,6 +10,7 @@ global $Settings; try { + $authCtx = new AuthenticationContext($Settings['Url']); $authCtx->acquireTokenForUser($Settings['UserName'],$Settings['Password']); diff --git a/src/GraphClient/ActiveDirectoryClient.php b/src/GraphClient/ActiveDirectoryClient.php deleted file mode 100644 index 0d5150de..00000000 --- a/src/GraphClient/ActiveDirectoryClient.php +++ /dev/null @@ -1,58 +0,0 @@ -getPendingRequest()->beforeExecuteQuery(function (RequestOptions $request,ClientAction $query){ - $request->Url .= "?api-version=1.0"; - }); - parent::executeQuery(); - } - - - - public function getTenantDetails() - { - if(!isset($this->tenantDetails)){ - $this->tenantDetails = new TenantDetailCollection($this,new ResourcePathEntity($this,null,"tenantDetails")); - } - return $this->tenantDetails; - } - - - public function getDevices() - { - if(!isset($this->devices)){ - $this->devices = new DeviceCollection($this,new ResourcePathEntity($this,null,"devices")); - } - return $this->devices; - } - - - /** - * @var TenantDetailCollection $tenantDetails - */ - private $tenantDetails; - - /** - * @var DeviceCollection $devices - */ - private $devices; -} diff --git a/src/GraphClient/GraphServiceClient.php b/src/GraphClient/GraphServiceClient.php new file mode 100644 index 00000000..fcf6196a --- /dev/null +++ b/src/GraphClient/GraphServiceClient.php @@ -0,0 +1,44 @@ +getPendingRequest()->beforeExecuteQuery(function (RequestOptions $request,ClientAction $query){ + }); + parent::executeQuery(); + } + + /** + * @return CurrentUserRequestContext + */ + public function getMe(){ + if(!isset($this->me)) + $this->me = new CurrentUserRequestContext($this,new ResourcePathEntity($this,null,"me")); + return $this->me; + } + + + + + +} diff --git a/src/OneDrive/Drive.php b/src/OneDrive/Drive.php index cd712f70..4043a8b8 100644 --- a/src/OneDrive/Drive.php +++ b/src/OneDrive/Drive.php @@ -22,7 +22,7 @@ public function getOwner(){ * @param string $value */ public function setOwner($value){ - return $this->setProperty("owner",$value); + $this->setProperty("owner",$value); } @@ -49,7 +49,7 @@ public function getFiles(){ * @param string $value */ public function setFiles($value){ - return $this->setProperty("files",$value); + $this->setProperty("files",$value); } } \ No newline at end of file diff --git a/src/Runtime/Auth/AuthenticationContext.php b/src/Runtime/Auth/AuthenticationContext.php index 8ae651b4..ff593fb6 100644 --- a/src/Runtime/Auth/AuthenticationContext.php +++ b/src/Runtime/Auth/AuthenticationContext.php @@ -110,16 +110,14 @@ public function exchangeRefreshToken($resource, $clientId, $clientSecret, $refre /** * @param string $resource * @param string $clientId - * @param string $clientSecret * @param UserCredentials $credentials */ - public function acquireTokenForUserCredential($resource, $clientId, $clientSecret, $credentials) + public function acquireTokenForUserCredential($resource, $clientId, $credentials) { $this->provider = new OAuthTokenProvider($this->authorityUrl); $parameters = array( 'grant_type' => 'password', 'client_id' => $clientId, - 'client_secret' => $clientSecret, 'username' => $credentials->Username, 'password' => $credentials->Password, 'scope' => 'openid', diff --git a/src/Runtime/ClientRequest.php b/src/Runtime/ClientRequest.php index 28cc7331..5f24e4e6 100644 --- a/src/Runtime/ClientRequest.php +++ b/src/Runtime/ClientRequest.php @@ -120,6 +120,7 @@ public function addQueryAndResultObject(ClientObject $clientObject, ODataQueryOp * @param RequestOptions $request * @param array $responseInfo * @return string + * @throws \Exception */ public function executeQueryDirect(RequestOptions $request,&$responseInfo=array()) { diff --git a/src/Runtime/ClientRuntimeContext.php b/src/Runtime/ClientRuntimeContext.php index eb4cad39..9a4d78e5 100644 --- a/src/Runtime/ClientRuntimeContext.php +++ b/src/Runtime/ClientRuntimeContext.php @@ -7,6 +7,8 @@ use Office365\PHP\Client\Runtime\OData\ODataFormat; use Office365\PHP\Client\Runtime\OData\ODataQueryOptions; use Office365\PHP\Client\Runtime\Utilities\RequestOptions; +use Office365\PHP\Client\Runtime\Utilities\Version; + /** * OData Runtime context for Office365 APIs @@ -40,6 +42,12 @@ class ClientRuntimeContext */ public $Format; + + /** + * @var Version $RequestSchemaVersion + */ + public $RequestSchemaVersion; + /** * REST client context ctor * @param string $serviceUrl @@ -137,6 +145,7 @@ public function executeQuery() /** * @param RequestOptions $options * @return string + * @throws \Exception */ public function executeQueryDirect(RequestOptions $options) { @@ -176,5 +185,11 @@ public function getPendingRequest() return $this->pendingRequest; } + /** + * @return Version + */ + public function getServerLibraryVersion(){ + return new Version(); + } } diff --git a/src/Runtime/OData/ODataBatchRequest.php b/src/Runtime/OData/ODataBatchRequest.php new file mode 100644 index 00000000..ad751443 --- /dev/null +++ b/src/Runtime/OData/ODataBatchRequest.php @@ -0,0 +1,49 @@ +createBoundary("batch_"); + while (($qry = array_shift($this->queries)) !== null) { + $request = $this->buildRequest($qry); + } + parent::executeQuery(); + } + + + function buildRequest(ClientAction $query) + { + return parent::buildRequest($query); // TODO: Change the autogenerated stub + } + + + /** + * Creates a string that can be used as a multipart request boundary. + * @param $prefix String to use as the start of the boundary string + * @return string Boundary string of the format: -- + */ + private function createBoundary($prefix){ + return $prefix . $this->hex16() . "-" . $this->hex16() . "-" . $this->hex16(); + } + + + /** + * Calculates a random 16 bit number and returns it in hexadecimal format. + * @return string A 16-bit number in hex format. + */ + private function hex16(){ + $val = dechex(floor((1 + ((float)rand()/(float)getrandmax())) * 0x10000)); + return substr($val,0,-1); + } + +} \ No newline at end of file diff --git a/src/Runtime/OData/ODataRequest.php b/src/Runtime/OData/ODataRequest.php index 4c01f59b..a8c57783 100644 --- a/src/Runtime/OData/ODataRequest.php +++ b/src/Runtime/OData/ODataRequest.php @@ -46,6 +46,7 @@ public function __construct(ClientRuntimeContext $context, ODataFormat $format) /** * Submit query to OData service + * @throws Exception */ public function executeQuery() { diff --git a/src/Runtime/OData/ODataResponse.php b/src/Runtime/OData/ODataResponse.php new file mode 100644 index 00000000..ea43efc9 --- /dev/null +++ b/src/Runtime/OData/ODataResponse.php @@ -0,0 +1,31 @@ +getServiceRootUrl() . "contextinfo"); $request->Method = HttpMethod::Post; diff --git a/src/SharePoint/Folder.php b/src/SharePoint/Folder.php index fac3dbcc..e7cec1e0 100644 --- a/src/SharePoint/Folder.php +++ b/src/SharePoint/Folder.php @@ -47,7 +47,6 @@ public function recycle(){ * Gets the collection of all files contained in the list folder. * You can add a file to a folder by using the Add method on the folder’s FileCollection resource. * @return FileCollection - * @throws \Exception */ public function getFiles() { diff --git a/src/SharePoint/ListCollection.php b/src/SharePoint/ListCollection.php index 823c92aa..794da253 100644 --- a/src/SharePoint/ListCollection.php +++ b/src/SharePoint/ListCollection.php @@ -20,7 +20,7 @@ public function getByTitle($title) { return new SPList( $this->getContext(), - new ResourcePathServiceOperation($this->getContext(),$this->getResourcePath(),"getByTitle",array($title)) + new ResourcePathServiceOperation($this->getContext(),$this->getResourcePath(),"getByTitle",array(rawurlencode($title))) ); } diff --git a/src/SharePoint/SPList.php b/src/SharePoint/SPList.php index 482ad0c1..42b80b2a 100644 --- a/src/SharePoint/SPList.php +++ b/src/SharePoint/SPList.php @@ -96,7 +96,6 @@ public function deleteObject() * Gets the set of permissions for the specified user * @param string $loginName * @return BasePermissions - * @throws \Exception */ public function getUserEffectivePermissions($loginName) { diff --git a/src/SharePoint/SecurableObject.php b/src/SharePoint/SecurableObject.php index 08bece5c..41badc5d 100644 --- a/src/SharePoint/SecurableObject.php +++ b/src/SharePoint/SecurableObject.php @@ -14,7 +14,6 @@ class SecurableObject extends ClientObject /** * Creates unique role assignments for the securable object. * @param bool $copyRoleAssignments - * @throws \Exception */ public function breakRoleInheritance($copyRoleAssignments) { diff --git a/src/SharePoint/ViewCollection.php b/src/SharePoint/ViewCollection.php index d70d8170..5f36e6d0 100644 --- a/src/SharePoint/ViewCollection.php +++ b/src/SharePoint/ViewCollection.php @@ -17,7 +17,7 @@ public function getByTitle($title) { return new View( $this->getContext(), - new ResourcePathServiceOperation($this->getContext(),$this->getResourcePath(),"getByTitle",array($title)) + new ResourcePathServiceOperation($this->getContext(),$this->getResourcePath(),"getByTitle",array(rawurlencode($title))) ); } diff --git a/tests/BatchTest.php b/tests/BatchTest.php new file mode 100644 index 00000000..66556baa --- /dev/null +++ b/tests/BatchTest.php @@ -0,0 +1,18 @@ +getSite(); + self::$context->load($site); + $web = $site->getRootWeb(); + self::$context->load($web); + self::$context->executeQuery(); + self::assertTrue($site->isPropertyAvailable("Title")); + self::assertTrue($web->isPropertyAvailable("Title")); + + } + +}*/ \ No newline at end of file