diff --git a/src/GraphServiceClient.php b/src/GraphServiceClient.php index 604331a2b23..5802c6cfe3d 100644 --- a/src/GraphServiceClient.php +++ b/src/GraphServiceClient.php @@ -9,6 +9,7 @@ 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; @@ -44,9 +45,13 @@ public function __construct( parent::__construct($requestAdapter); return; } - parent::__construct(new GraphRequestAdapter( - new GraphPhpLeagueAuthenticationProvider($tokenRequestContext, $scopes, $nationalCloud) - )); + $defaultRequestAdapter = new GraphRequestAdapter( + GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider( + new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud) + ) + ); + $defaultRequestAdapter->setBaseUrl("$nationalCloud/beta"); + parent::__construct($defaultRequestAdapter); } /** diff --git a/tests/GraphServiceClientTest.php b/tests/GraphServiceClientTest.php index a3d113a654e..50d48bf830f 100644 --- a/tests/GraphServiceClientTest.php +++ b/tests/GraphServiceClientTest.php @@ -121,4 +121,10 @@ function (RequestInterface $request) { // cache is populated $this->assertInstanceOf(AccessToken::class, $customCache->getTokenWithContext($tokenRequestContext)); } + + public function testNationalCloudUsed(): void + { + $client = new GraphServiceClient(new ClientCredentialContext('tenant', 'client', 'secret'), [], NationalCloud::US_GOV); + $this->assertEquals(NationalCloud::US_GOV.'/beta', $client->getRequestAdapter()->getBaseUrl()); + } }