Skip to content

Commit

Permalink
Merge pull request #1628 from microsoftgraph/fix/national-clouds
Browse files Browse the repository at this point in the history
fix: Use provided national cloud as base url
  • Loading branch information
Ndiritu authored Jan 8, 2025
2 parents 3bd2bd8 + d40f2a2 commit cf1181a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/GraphServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Microsoft\Graph;

use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;
use Microsoft\Graph\Core\NationalCloud;
use Microsoft\Graph\Generated\BaseGraphClient;
Expand Down Expand Up @@ -45,9 +46,13 @@ public function __construct(
parent::__construct($requestAdapter);
return;
}
parent::__construct(new GraphRequestAdapter(new GraphPhpLeagueAuthenticationProvider(
$tokenRequestContext, $scopes, $nationalCloud
)));
$defaultRequestAdapter = new GraphRequestAdapter(
GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud)
)
);
$defaultRequestAdapter->setBaseUrl($nationalCloud.'/v1.0');
parent::__construct($defaultRequestAdapter);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/GraphServiceClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit cf1181a

Please sign in to comment.