From d40f2a2485a0ebd69e18c1cd1509983e69ee2f4e Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 10 Dec 2024 12:34:08 +0300 Subject: [PATCH] fix: Use provided national cloud as base URL and map it to the correct authentication endpoint --- src/GraphServiceClient.php | 11 ++++++++--- tests/GraphServiceClientTest.php | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/GraphServiceClient.php b/src/GraphServiceClient.php index b2a381ec699..497d9259b8e 100644 --- a/src/GraphServiceClient.php +++ b/src/GraphServiceClient.php @@ -8,6 +8,7 @@ namespace Microsoft\Graph; +use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider; use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider; use Microsoft\Graph\Core\NationalCloud; use Microsoft\Graph\Generated\BaseGraphClient; @@ -45,9 +46,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.'/v1.0'); + parent::__construct($defaultRequestAdapter); } /** diff --git a/tests/GraphServiceClientTest.php b/tests/GraphServiceClientTest.php index 3b2a9265904..f0124252968 100644 --- a/tests/GraphServiceClientTest.php +++ b/tests/GraphServiceClientTest.php @@ -126,4 +126,10 @@ function (RequestInterface $request) { $this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($newTokenRequestContext)); $this->assertEquals($this->testJWT, $newCache->getTokenWithContext($newTokenRequestContext)->getToken()); } + + public function testNationalCloudUsed(): void + { + $client = new GraphServiceClient(new ClientCredentialContext('tenant', 'client', 'secret'), [], NationalCloud::US_GOV); + $this->assertEquals(NationalCloud::US_GOV.'/v1.0', $client->getRequestAdapter()->getBaseUrl()); + } }