From 37e4d4642bf850065e769109ead6b6e1c9493d30 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 10 Dec 2024 12:35:49 +0300 Subject: [PATCH 1/3] fix: Mark nationalCloud constructor parameter in GraphPhpLeagueAuthenticationProvider as deprecated --- .../GraphPhpLeagueAuthenticationProvider.php | 5 ++--- .../GraphPhpLeagueAuthenticationProviderTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Authentication/GraphPhpLeagueAuthenticationProvider.php b/src/Authentication/GraphPhpLeagueAuthenticationProvider.php index 2045d32b..a6edb85f 100644 --- a/src/Authentication/GraphPhpLeagueAuthenticationProvider.php +++ b/src/Authentication/GraphPhpLeagueAuthenticationProvider.php @@ -24,13 +24,12 @@ class GraphPhpLeagueAuthenticationProvider extends PhpLeagueAuthenticationProvid /** * @param TokenRequestContext $tokenRequestContext * @param array $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 string $nationalCloud @deprecated Parameter is not passed up to the parent class. Use createWithAccessTokenProvider() instead */ public function __construct( TokenRequestContext $tokenRequestContext, array $scopes = [], - string $nationalCloud = NationalCloud::GLOBAL + string $nationalCloud = NationalCloud::GLOBAL // @deprecated parameter is not passed up to the parent class. Use createWithAccessTokenProvider() instead ) { $accessTokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud); diff --git a/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php b/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php index 9549e5c5..0ee8778e 100644 --- a/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php +++ b/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php @@ -4,6 +4,7 @@ use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider; use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider; +use Microsoft\Graph\Core\NationalCloud; use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext; use PHPUnit\Framework\TestCase; @@ -15,4 +16,12 @@ public function testSuccessfullyInitializesClass(): void $leagueAuthProvider = new GraphPhpLeagueAuthenticationProvider($context, []); $this->assertNotEmpty($leagueAuthProvider->getAccessTokenProvider()->getAllowedHostsValidator()->getAllowedHosts()); } + + public function testNationalCloudUrlIsUsed(): void + { + $context = new ClientCredentialContext('tenant', 'clientId', 'secret'); + $leagueAuthProvider = new GraphPhpLeagueAuthenticationProvider($context, [], NationalCloud::US_GOV); + $this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/authorize', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAuthorizationUrl()); + $this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/token', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAccessTokenUrl([])); + } } From b71e68f8c8d8e3415fe20c2ce55278f6d6d3f4b7 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Wed, 8 Jan 2025 15:49:29 +0300 Subject: [PATCH 2/3] Add unit test for setting national cloud in auth provider --- .../GraphPhpLeagueAuthenticationProviderTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php b/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php index 0ee8778e..6e7765ba 100644 --- a/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php +++ b/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php @@ -20,7 +20,9 @@ public function testSuccessfullyInitializesClass(): void public function testNationalCloudUrlIsUsed(): void { $context = new ClientCredentialContext('tenant', 'clientId', 'secret'); - $leagueAuthProvider = new GraphPhpLeagueAuthenticationProvider($context, [], NationalCloud::US_GOV); + $leagueAuthProvider = GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider( + new GraphPhpLeagueAccessTokenProvider($context, [], NationalCloud::US_GOV) + ); $this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/authorize', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAuthorizationUrl()); $this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/token', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAccessTokenUrl([])); } From 9c7788e82f63857a7bff1bc6d11e019878b1ea40 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Wed, 8 Jan 2025 16:06:24 +0300 Subject: [PATCH 3/3] fix PHPStan failure --- src/GraphClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphClientFactory.php b/src/GraphClientFactory.php index 379d8387..d61520b7 100644 --- a/src/GraphClientFactory.php +++ b/src/GraphClientFactory.php @@ -80,7 +80,7 @@ private static function getInstance(): GraphClientFactory { * Set national cloud to be used as the base URL * * @param string $nationalCloud - * @return $this + * @return static * @throws InvalidArgumentException if $nationalCloud is empty or an invalid national cloud Host */ public static function setNationalCloud(string $nationalCloud = NationalCloud::GLOBAL): GraphClientFactory {