1. Go to this page and download the library: Download owncloud/ocis-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
owncloud / ocis-php-sdk example snippets
$ocis = new Ocis('https://example.ocis.com', $accessToken);
$ocis = new Ocis('https://education.ocis.com', null, [], $educationAccessToken);
// get the personal drive of the authorized user
// `getMyDrives` returns all drives that the user is a member of
// but in this example the result is filtered to only return
// the personal drive (parameter 3 = DriveType::PERSONAL)
$drives = $ocis->getMyDrives(
DriveOrder::NAME,
OrderDirection::ASC,
DriveType::PERSONAL
);
// get the drive id
$id = $drives[0]->getId();
// get the name of the drive
$name = $drives[0]->getName();
// get a link to the drive that can be opened in a browser and will lead the user to the web interface
$webUrl = $drives[0]->getWebUrl();
// create a folder inside the drive
$drives[0]->createFolder("/documents");
// upload a file to the drive
$drives[0]->uploadFile("/documents/myfile.txt", "Hello World!");
// get an array of all resources of the "/documents" folder inside the drive
$resources = $drives[0]->getResources("/documents");
// find all users with a specific surname
$users = $ocis->getUsers("einstein")[0];
// get all drives of type project
$drives = $ocis->getMyDrives(
DriveOrder::NAME,
OrderDirection::ASC,
DriveType::PROJECT
);
// get the drive named 'game'
foreach ($drives as $drive) {
if ($drive->getName) === 'game' {
$gameDrive = $drive;
break;
}
}
// get all roles that are possible for that drive
$driveRoles = $gameDrive->getRoles();
// get the role that is allowed to view, download, upload, edit, add, delete and manage members
foreach ($driveRoles as $role) {
if ($role->getDisplayName() === 'Manager') {
$managerRole = $role;
break;
}
}
// invite user einstein on project drive 'game' with manager permission
$gameDrive->invite($users, $managerRole);
// get the resources of a subfolder inside a drive
$resources = $drive->getResources("/documents");
// get all roles that are possible for that particular resource
$roles = $resources[0]->getRoles();
// find the role that is allowed to read and write the shared file or folder
for ($roles as $role) {
if ($role->getDisplayName() === 'Can edit') {
$editorRole = $role;
break;
}
}
// find all users with a specific surname
$users = $ocis->getUsers("einstein")[0];
// share the resource with the users
$resources[0]->invite($users, $editorRole);
// create education user
$educationUsers = $ocis->createEducationUser()
// list all education user
$educationUsers = $ocis->getEducationUsers()
// list education user by id
$educationUsers = $ocis->getEducationUserById()
// delete education user
$educationUser[0]->delete()
acile\OpenIDClient\Client\ClientBuilder;
use Facile\OpenIDClient\Issuer\IssuerBuilder;
use Facile\OpenIDClient\Client\Metadata\ClientMetadata;
use Facile\OpenIDClient\Service\Builder\AuthorizationServiceBuilder;
use Nyholm\Psr7\ServerRequest;
$issuer = (new IssuerBuilder())
->build('https://example.ocis.com');
$clientMetadata = ClientMetadata::fromArray([
'client_id' => 'client_id',
'client_secret' => 'client_secret',
'redirect_uris' => [
'http://url-of-this-file',
],
]);
$client = (new ClientBuilder())
->setIssuer($issuer)
->setClientMetadata($clientMetadata)
->build();
$authorizationService = (new AuthorizationServiceBuilder())->build();
$redirectAuthorizationUri = $authorizationService->getAuthorizationUri(
$client,
['scope'=>'openid profile email offline_access']
);
if(!isset($_REQUEST["code"])) {
header('Location: ' . $redirectAuthorizationUri);
} else {
$serverRequest = new ServerRequest('GET', $_SERVER['REQUEST_URI']);
$callbackParams = $authorizationService->getCallbackParams($serverRequest, $client);
$tokenSet = $authorizationService->callback($client, $callbackParams);
// store access and refresh token in database
$accessToken = $tokenSet->getAccessToken();
echo 'AccessToken : ' . $accessToken;
echo '<hr>';
$refreshToken = $tokenSet->getRefreshToken();
echo 'RefreshToken : ' . $refreshToken;
echo '<hr>';
// use this code to get new access token when expired
$tokenSet = $authorizationService->refresh($client, $refreshToken);
$accessToken = $tokenSet->getAccessToken();
echo 'NewAccessToken : ' . $accessToken;
}
...
use Facile\OpenIDClient\Issuer\Metadata\Provider\MetadataProviderBuilder;
use Facile\JoseVerifier\JWK\JwksProviderBuilder;
use Symfony\Component\HttpClient\Psr18Client;
use Symfony\Component\HttpClient\CurlHttpClient;
$symHttpClient = new CurlHttpClient([
'verify_peer' => false,
'verify_host' => false
]);
$httpClient = new Psr18Client($symHttpClient);
$metadataProviderBuilder = (new MetadataProviderBuilder())
->setHttpClient($httpClient);
$jwksProviderBuilder = (new JwksProviderBuilder())
->setHttpClient($httpClient);
$issuer = (new IssuerBuilder())
->setMetadataProviderBuilder($metadataProviderBuilder)
->setJwksProviderBuilder($jwksProviderBuilder)
->build('https://example.ocis.com');
...
$client = (new ClientBuilder())
->setHttpClient($httpClient)
->setIssuer($issuer)
->setClientMetadata($clientMetadata)
->build();
$authorizationService = (new AuthorizationServiceBuilder())
->setHttpClient($httpClient)
->build();
...