Skip to content

Commit

Permalink
Merge pull request #6 from softonic/bugfix/improve-readability
Browse files Browse the repository at this point in the history
improve readability
  • Loading branch information
rccrdpccl authored Aug 21, 2017
2 parents 82b3c03 + b187c48 commit 07425ea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/AccessTokenCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AccessTokenCacheHandler
{
const CACHE_KEY_PREFIX = 'oauth2-token-';

private $cache;

public function __construct(CacheItemPoolInterface $cache)
{
$this->cache = $cache;
Expand Down
8 changes: 6 additions & 2 deletions src/RetryOnAuthorizationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public function __invoke(
ResponseInterface $response = null,
\Exception $exception = null
): bool {
$statusCode = $response->getStatusCode();
if ($retries < 1 && $statusCode === 401) {
if ($this->isUnauthorizedResponse($retries, $response)) {
$this->cacheHandler->deleteItemByProvider($this->provider, $this->config);
return true;
}
return false;
}

private function isUnauthorizedResponse(int $retries, ResponseInterface $response = null)
{
return !empty($response) && $retries < 1 && $response->getStatusCode() === 401;
}
}
2 changes: 1 addition & 1 deletion tests/RetryOnAuthorizationErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testRetryOnceOn401Response()
$mockProvider = $this->createMock(\League\OAuth2\Client\Provider\AbstractProvider::class);
$mockCacheHandler = $this->createMock(\Softonic\OAuth2\Guzzle\Middleware\AccessTokenCacheHandler::class);

$mockResponse->expects($this->exactly(2))
$mockResponse->expects($this->exactly(1))
->method('getStatusCode')
->willReturn(401);

Expand Down

0 comments on commit 07425ea

Please sign in to comment.