Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Authentication/GraphPhpLeagueAuthenticationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ class GraphPhpLeagueAuthenticationProvider extends PhpLeagueAuthenticationProvid
/**
* @param TokenRequestContext $tokenRequestContext
* @param array<string> $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);
Expand Down
2 changes: 1 addition & 1 deletion src/GraphClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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([]));
}
}
Loading