From 4323b09ce0a8aa62ac103c5ce703e1849399ad60 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 --- src/GraphServiceClient.php | 6 ++++-- tests/GraphServiceClientTest.php | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GraphServiceClient.php b/src/GraphServiceClient.php index b2a381ec699..4f08b999e91 100644 --- a/src/GraphServiceClient.php +++ b/src/GraphServiceClient.php @@ -45,9 +45,11 @@ public function __construct( parent::__construct($requestAdapter); return; } - parent::__construct(new GraphRequestAdapter(new GraphPhpLeagueAuthenticationProvider( + $defaultRequestAdapter = new GraphRequestAdapter(new GraphPhpLeagueAuthenticationProvider( $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()); + } }