Skip to content

Commit

Permalink
3.1.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Apr 21, 2024
1 parent d32d8fb commit a3b445b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.1.2] - 2024-04-21

### Added

- `GraphServiceClient::withUserCredentials` and `GraphServiceClient::withClientSecret` methods introduced

### Fixed

- #337: Don't try to retrieve next set of items when using an iterator, if no next items are expected to exist

## [3.0.3] - 2023-07-15

Expand Down
18 changes: 5 additions & 13 deletions examples/OneDrive/DownloadFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@

use Office365\GraphServiceClient;
use Office365\OneDrive\DriveItems\DriveItem;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;


function acquireToken()
{
$resource = "https://graph.microsoft.com";
$settings = include('../../tests/Settings.php');
$provider = new AADTokenProvider($settings['TenantName']);
return $provider->acquireTokenForPassword($resource, $settings['ClientId'],
new UserCredentials($settings['UserName'], $settings['Password']));
}

$client = new GraphServiceClient("acquireToken");
$settings = include('../../tests/Settings.php');
$client = GraphServiceClient::withUserCredentials(
$settings['TenantName'], $settings['ClientId'], $settings['UserName'], $settings['Password']
);

$items = $client->getMe()->getDrive()->getRoot()->getChildren()->get()->executeQuery();
$items = $client->getMe()->getDrive()->getRoot()->getChildren()->top(10)->get()->executeQuery();
/** @var DriveItem $item */
foreach ($items as $item){
if($item->isFile()){
Expand Down
14 changes: 2 additions & 12 deletions examples/Reports/getReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@


use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\ClientCredential;


require_once '../vendor/autoload.php';

function acquireToken()
{
$resource = "https://graph.microsoft.com";
$settings = include('../../tests/Settings.php');
$provider = new AADTokenProvider($settings['TenantName']);
return $provider->acquireTokenForClientCredential($resource,
new ClientCredential($settings['ClientId'], $settings['ClientSecret']),["/.default"]);
}

$client = new GraphServiceClient("acquireToken");
$settings = include('../../tests/Settings.php');
$client = GraphServiceClient::withClientSecret($settings['TenantName'], $settings['ClientId'], $settings['ClientSecret']);
$result = $client->getReports()->getOffice365ActivationCounts()->executeQuery();
var_dump($result->getValue());

Expand Down
17 changes: 17 additions & 0 deletions src/GraphServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Office365\OneDrive\Sites\Site;
use Office365\Reports\ReportRoot;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\ClientCredential;
use Office365\Runtime\Auth\UserCredentials;
use Office365\Runtime\ClientRuntimeContext;
use Office365\Runtime\Actions\DeleteEntityQuery;
Expand Down Expand Up @@ -66,6 +67,22 @@ public static function withUserCredentials($tenantName, $clientId, $userName, $p
});
}

/**
* @param $tenantName
* @param $clientId
* @param $clientSecret
* @return GraphServiceClient
*/
public static function withClientSecret($tenantName, $clientId, $clientSecret)
{
return new GraphServiceClient(function () use ($clientSecret, $clientId, $tenantName) {
$resource = "https://graph.microsoft.com";
$provider = new AADTokenProvider($tenantName);
return $provider->acquireTokenForClientCredential($resource,
new ClientCredential($clientId, $clientSecret),["/.default"]);
});
}

/**
* @return ODataRequest
*/
Expand Down

0 comments on commit a3b445b

Please sign in to comment.