From 2df52a14858670727e336b3ae3846e3c734a892f Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 26 Nov 2024 11:31:07 +0300 Subject: [PATCH 1/2] fix: Wrong token cache test assertion --- tests/GraphServiceClientTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/GraphServiceClientTest.php b/tests/GraphServiceClientTest.php index 06d418d5218..5754fe24692 100644 --- a/tests/GraphServiceClientTest.php +++ b/tests/GraphServiceClientTest.php @@ -100,6 +100,7 @@ function (RequestInterface $request) { // cache is populated $this->assertInstanceOf(AccessToken::class, $customCache->getTokenWithContext($tokenRequestContext)); + $this->assertEquals($this->testJWT, $customCache->getTokenWithContext($tokenRequestContext)->getToken()); // hydrate another cache for follow-up request $newCache = new InMemoryAccessTokenCache($tokenRequestContext, $customCache->getTokenWithContext($tokenRequestContext)); @@ -119,6 +120,6 @@ function (RequestInterface $request) { $me = $client->me()->get()->wait(); // cache is populated - $this->assertInstanceOf(AccessToken::class, $customCache->getTokenWithContext($tokenRequestContext)); + $this->assertInstanceOf(AccessToken::class, $newCache->getTokenWithContext($tokenRequestContext)); } } From f0895c9aea7dcfdc82f8cdbb6cfa363859bc71f0 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 26 Nov 2024 11:40:10 +0300 Subject: [PATCH 2/2] Ensure new token cache contains the same token --- tests/GraphServiceClientTest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/GraphServiceClientTest.php b/tests/GraphServiceClientTest.php index 5754fe24692..3b2a9265904 100644 --- a/tests/GraphServiceClientTest.php +++ b/tests/GraphServiceClientTest.php @@ -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; @@ -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( @@ -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()); } }