Skip to content

Commit

Permalink
Ensure new token cache contains the same token
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Nov 26, 2024
1 parent 2df52a1 commit f0895c9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/GraphServiceClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use League\OAuth2\Client\Grant\AuthorizationCode;
use League\OAuth2\Client\Token\AccessToken;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;
Expand Down Expand Up @@ -103,10 +104,12 @@ function (RequestInterface $request) {
$this->assertEquals($this->testJWT, $customCache->getTokenWithContext($tokenRequestContext)->getToken());

// hydrate another cache for follow-up request
$newCache = new InMemoryAccessTokenCache($tokenRequestContext, $customCache->getTokenWithContext($tokenRequestContext));
$previousAccessToken = $customCache->getTokenWithContext($tokenRequestContext);
$newTokenRequestContext = new AuthorizationCodeContext('tenant', 'clientId', 'clientSecret', 'redirectUri', 'code');
$newCache = new InMemoryAccessTokenCache($newTokenRequestContext, $previousAccessToken);
$accessTokenProvider = GraphPhpLeagueAccessTokenProvider::createWithCache(
$newCache,
$tokenRequestContext,
$newTokenRequestContext,
$scopes
);
$client = GraphServiceClient::createWithRequestAdapter(
Expand All @@ -120,6 +123,7 @@ function (RequestInterface $request) {

$me = $client->me()->get()->wait();
// cache is populated
$this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($tokenRequestContext));
$this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($newTokenRequestContext));
$this->assertEquals($this->testJWT, $newCache->getTokenWithContext($newTokenRequestContext)->getToken());
}
}

0 comments on commit f0895c9

Please sign in to comment.