Skip to content

Commit f0895c9

Browse files
committed
Ensure new token cache contains the same token
1 parent 2df52a1 commit f0895c9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/GraphServiceClientTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Handler\MockHandler;
77
use GuzzleHttp\Psr7\Response;
8+
use League\OAuth2\Client\Grant\AuthorizationCode;
89
use League\OAuth2\Client\Token\AccessToken;
910
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
1011
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;
@@ -103,10 +104,12 @@ function (RequestInterface $request) {
103104
$this->assertEquals($this->testJWT, $customCache->getTokenWithContext($tokenRequestContext)->getToken());
104105

105106
// hydrate another cache for follow-up request
106-
$newCache = new InMemoryAccessTokenCache($tokenRequestContext, $customCache->getTokenWithContext($tokenRequestContext));
107+
$previousAccessToken = $customCache->getTokenWithContext($tokenRequestContext);
108+
$newTokenRequestContext = new AuthorizationCodeContext('tenant', 'clientId', 'clientSecret', 'redirectUri', 'code');
109+
$newCache = new InMemoryAccessTokenCache($newTokenRequestContext, $previousAccessToken);
107110
$accessTokenProvider = GraphPhpLeagueAccessTokenProvider::createWithCache(
108111
$newCache,
109-
$tokenRequestContext,
112+
$newTokenRequestContext,
110113
$scopes
111114
);
112115
$client = GraphServiceClient::createWithRequestAdapter(
@@ -120,6 +123,7 @@ function (RequestInterface $request) {
120123

121124
$me = $client->me()->get()->wait();
122125
// cache is populated
123-
$this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($tokenRequestContext));
126+
$this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($newTokenRequestContext));
127+
$this->assertEquals($this->testJWT, $newCache->getTokenWithContext($newTokenRequestContext)->getToken());
124128
}
125129
}

0 commit comments

Comments
 (0)