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/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 { diff --git a/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php b/tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php index 9549e5c5..6e7765ba 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,14 @@ 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 = 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([])); + } }