Skip to content

Commit a3b445b

Browse files
committed
3.1.2 release
1 parent d32d8fb commit a3b445b

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [3.1.2] - 2024-04-21
12+
13+
### Added
14+
15+
- `GraphServiceClient::withUserCredentials` and `GraphServiceClient::withClientSecret` methods introduced
16+
17+
### Fixed
18+
19+
- #337: Don't try to retrieve next set of items when using an iterator, if no next items are expected to exist
1120

1221
## [3.0.3] - 2023-07-15
1322

examples/OneDrive/DownloadFiles.php

+5-13
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@
44

55
use Office365\GraphServiceClient;
66
use Office365\OneDrive\DriveItems\DriveItem;
7-
use Office365\Runtime\Auth\AADTokenProvider;
8-
use Office365\Runtime\Auth\UserCredentials;
97

108

11-
function acquireToken()
12-
{
13-
$resource = "https://graph.microsoft.com";
14-
$settings = include('../../tests/Settings.php');
15-
$provider = new AADTokenProvider($settings['TenantName']);
16-
return $provider->acquireTokenForPassword($resource, $settings['ClientId'],
17-
new UserCredentials($settings['UserName'], $settings['Password']));
18-
}
19-
20-
$client = new GraphServiceClient("acquireToken");
9+
$settings = include('../../tests/Settings.php');
10+
$client = GraphServiceClient::withUserCredentials(
11+
$settings['TenantName'], $settings['ClientId'], $settings['UserName'], $settings['Password']
12+
);
2113

22-
$items = $client->getMe()->getDrive()->getRoot()->getChildren()->get()->executeQuery();
14+
$items = $client->getMe()->getDrive()->getRoot()->getChildren()->top(10)->get()->executeQuery();
2315
/** @var DriveItem $item */
2416
foreach ($items as $item){
2517
if($item->isFile()){

examples/Reports/getReports.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22

33

44
use Office365\GraphServiceClient;
5-
use Office365\Runtime\Auth\AADTokenProvider;
6-
use Office365\Runtime\Auth\ClientCredential;
75

86

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

11-
function acquireToken()
12-
{
13-
$resource = "https://graph.microsoft.com";
14-
$settings = include('../../tests/Settings.php');
15-
$provider = new AADTokenProvider($settings['TenantName']);
16-
return $provider->acquireTokenForClientCredential($resource,
17-
new ClientCredential($settings['ClientId'], $settings['ClientSecret']),["/.default"]);
18-
}
19-
20-
$client = new GraphServiceClient("acquireToken");
9+
$settings = include('../../tests/Settings.php');
10+
$client = GraphServiceClient::withClientSecret($settings['TenantName'], $settings['ClientId'], $settings['ClientSecret']);
2111
$result = $client->getReports()->getOffice365ActivationCounts()->executeQuery();
2212
var_dump($result->getValue());
2313

src/GraphServiceClient.php

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Office365\OneDrive\Sites\Site;
1414
use Office365\Reports\ReportRoot;
1515
use Office365\Runtime\Auth\AADTokenProvider;
16+
use Office365\Runtime\Auth\ClientCredential;
1617
use Office365\Runtime\Auth\UserCredentials;
1718
use Office365\Runtime\ClientRuntimeContext;
1819
use Office365\Runtime\Actions\DeleteEntityQuery;
@@ -66,6 +67,22 @@ public static function withUserCredentials($tenantName, $clientId, $userName, $p
6667
});
6768
}
6869

70+
/**
71+
* @param $tenantName
72+
* @param $clientId
73+
* @param $clientSecret
74+
* @return GraphServiceClient
75+
*/
76+
public static function withClientSecret($tenantName, $clientId, $clientSecret)
77+
{
78+
return new GraphServiceClient(function () use ($clientSecret, $clientId, $tenantName) {
79+
$resource = "https://graph.microsoft.com";
80+
$provider = new AADTokenProvider($tenantName);
81+
return $provider->acquireTokenForClientCredential($resource,
82+
new ClientCredential($clientId, $clientSecret),["/.default"]);
83+
});
84+
}
85+
6986
/**
7087
* @return ODataRequest
7188
*/

0 commit comments

Comments
 (0)