-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGraphServiceClient.php
More file actions
103 lines (95 loc) · 3.8 KB
/
GraphServiceClient.php
File metadata and controls
103 lines (95 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*/
namespace Microsoft\Graph\Beta;
use Microsoft\Graph\Beta\Generated\Users\Item\UserItemRequestBuilder;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;
use Microsoft\Graph\Core\NationalCloud;
use Microsoft\Kiota\Abstractions\Authentication\AuthenticationProvider;
use Microsoft\Kiota\Abstractions\RequestAdapter;
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
use Microsoft\Kiota\Authentication\Oauth\TokenRequestContext;
/**
* Class GraphServiceClient
*
* @package Microsoft\Graph
* @copyright 2022 Microsoft Corporation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://developer.microsoft.com/graph
*/
class GraphServiceClient extends Generated\BaseGraphClient
{
/**
* @param TokenRequestContext $tokenRequestContext
* @param array<string> $scopes Defaults to "https://[graph national cloud host]/.default" scope
* @param string $nationalCloud Defaults to https://graph.microsoft.com. See
* https://learn.microsoft.com/en-us/graph/deployments
* @param RequestAdapter|null $requestAdapter Use createWithRequestAdapter() to set the request adapter.
*/
public function __construct(
TokenRequestContext $tokenRequestContext,
array $scopes = [],
string $nationalCloud = NationalCloud::GLOBAL,
?RequestAdapter $requestAdapter = null
)
{
if ($requestAdapter) {
parent::__construct($requestAdapter);
return;
}
$defaultRequestAdapter = new GraphRequestAdapter(
GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud)
)
);
$defaultRequestAdapter->setBaseUrl("$nationalCloud/beta");
parent::__construct($defaultRequestAdapter);
}
/**
* Get an instance of GraphServiceClient that uses $requestAdapter
* @param RequestAdapter $requestAdapter
* @param string $nationalCloud Sets $requestAdapter baseURL if none has already been set
* Defaults to https://graph.microsoft.com. See https://learn.microsoft.com/en-us/graph/deployments
* @return GraphServiceClient
*/
public static function createWithRequestAdapter(
RequestAdapter $requestAdapter,
string $nationalCloud = NationalCloud::GLOBAL
): GraphServiceClient
{
if (!$requestAdapter->getBaseUrl()) {
$requestAdapter->setBaseUrl("$nationalCloud/beta");
}
$placeholder = new ClientCredentialContext('tenant', 'client', 'secret');
return new GraphServiceClient($placeholder, [], 'placeholder', $requestAdapter);
}
public static function createWithAuthenticationProvider(
AuthenticationProvider $authenticationProvider,
string $nationalCloud = NationalCloud::GLOBAL
): self
{
return GraphServiceClient::createWithRequestAdapter(new GraphRequestAdapter($authenticationProvider), $nationalCloud);
}
/**
* Returns the request adapter instance in use
*
* @return RequestAdapter
*/
public function getRequestAdapter(): RequestAdapter
{
return $this->requestAdapter;
}
/**
* A method that abstracts the /me endpoint and users /users/{{user-id}} under
* the hood.
*/
public function me(): UserItemRequestBuilder {
$urlTplParameters = $this->pathParameters;
$urlTplParameters['user%2Did'] = 'me-token-to-replace';
return new UserItemRequestBuilder($urlTplParameters, $this->requestAdapter);
}
}