Skip to content

Commit

Permalink
Fix OAuth getCacheKey method (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea De Pirro authored Aug 7, 2019
1 parent e0ba25c commit 4051b3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ matrix:
- php: 7.0
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: 7.1
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: 7.2
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
- php: 7.3
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
- php: master
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=false
Expand Down
4 changes: 3 additions & 1 deletion src/AccessTokenCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function deleteItemByProvider(OAuth2Provider $provider, array $options):

public function getCacheKey(OAuth2Provider $provider, array $options): string
{
return static::CACHE_KEY_PREFIX . md5(print_r($provider, true) . serialize($options));
parse_str(parse_url($provider->getAuthorizationUrl(), PHP_URL_QUERY), $query);
return static::CACHE_KEY_PREFIX
. md5($provider->getBaseAuthorizationUrl() . ($query['client_id'] ?? '') . serialize($options));
}
}
8 changes: 4 additions & 4 deletions tests/AccessTokenCacheHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

class AccessTokenCacheHandlerTest extends TestCase
{
public function testGetCacheKeyIsDifferentBetweenProviders()
public function testGetCacheKeyIsDifferentBetweenOauthClients()
{
$mockCache = $this->createMock(\Psr\Cache\CacheItemPoolInterface::class);

$options = [];
$providerA = $this->createMock(\League\OAuth2\Client\Provider\AbstractProvider::class);
$providerA->expects($this->any())
->method('getAccessToken')
->willReturn('a');
->method('getAuthorizationUrl')
->willReturn('http://example.com?client_id=a');

$providerB = $this->createMock(\League\OAuth2\Client\Provider\AbstractProvider::class);
$providerB->expects($this->any())
->method('getAccessToken')
->willReturn('b');
->willReturn('http://example.com?client_id=b');

$cacheHandler = new AccessTokenCacheHandler($mockCache);
$this->assertNotEquals(
Expand Down

0 comments on commit 4051b3c

Please sign in to comment.