Skip to content

Commit 2ae949a

Browse files
authored
Merge pull request #201 from microsoftgraph/fix/national-cloud
Deprecate national cloud parameter in access token provider constructor
2 parents 82598c5 + 9c7788e commit 2ae949a

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/Authentication/GraphPhpLeagueAuthenticationProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ class GraphPhpLeagueAuthenticationProvider extends PhpLeagueAuthenticationProvid
2424
/**
2525
* @param TokenRequestContext $tokenRequestContext
2626
* @param array<string> $scopes defaults to ["https://[graph national cloud host]/.default"] scope
27-
* @param string $nationalCloud defaults to https://graph.microsoft.com. See
28-
* https://learn.microsoft.com/en-us/graph/deployments
27+
* @param string $nationalCloud @deprecated Parameter is not passed up to the parent class. Use createWithAccessTokenProvider() instead
2928
*/
3029
public function __construct(
3130
TokenRequestContext $tokenRequestContext,
3231
array $scopes = [],
33-
string $nationalCloud = NationalCloud::GLOBAL
32+
string $nationalCloud = NationalCloud::GLOBAL // @deprecated parameter is not passed up to the parent class. Use createWithAccessTokenProvider() instead
3433
)
3534
{
3635
$accessTokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud);

src/GraphClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static function getInstance(): GraphClientFactory {
8080
* Set national cloud to be used as the base URL
8181
*
8282
* @param string $nationalCloud
83-
* @return $this
83+
* @return static
8484
* @throws InvalidArgumentException if $nationalCloud is empty or an invalid national cloud Host
8585
*/
8686
public static function setNationalCloud(string $nationalCloud = NationalCloud::GLOBAL): GraphClientFactory {

tests/Authentication/GraphPhpLeagueAuthenticationProviderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
66
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;
7+
use Microsoft\Graph\Core\NationalCloud;
78
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
89
use PHPUnit\Framework\TestCase;
910

@@ -15,4 +16,14 @@ public function testSuccessfullyInitializesClass(): void
1516
$leagueAuthProvider = new GraphPhpLeagueAuthenticationProvider($context, []);
1617
$this->assertNotEmpty($leagueAuthProvider->getAccessTokenProvider()->getAllowedHostsValidator()->getAllowedHosts());
1718
}
19+
20+
public function testNationalCloudUrlIsUsed(): void
21+
{
22+
$context = new ClientCredentialContext('tenant', 'clientId', 'secret');
23+
$leagueAuthProvider = GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
24+
new GraphPhpLeagueAccessTokenProvider($context, [], NationalCloud::US_GOV)
25+
);
26+
$this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/authorize', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAuthorizationUrl());
27+
$this->assertEquals('https://login.microsoftonline.us/tenant/oauth2/v2.0/token', $leagueAuthProvider->getAccessTokenProvider()->getOauthProvider()->getBaseAccessTokenUrl([]));
28+
}
1829
}

0 commit comments

Comments
 (0)