Skip to content

Commit

Permalink
Better handling of corrupted tokens
Browse files Browse the repository at this point in the history
When restoring an existing token from persistence, the token may be
in an unreadable format, or otherwise corrupt.  This commit ensures
the corrupt file is discarded and a new access token is obtained.
  • Loading branch information
kamermans committed Oct 23, 2017
1 parent 55e469f commit 16152ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Persistence/DoctrineCacheTokenPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function restoreToken(TokenInterface $token)
{
$data = $this->cache->fetch($this->cacheKey);

if (false === $data) {
if (!is_array($data)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/FileTokenPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function restoreToken(TokenInterface $token)
return null;
}

$data = @json_decode(file_get_contents($this->filepath), true);
$data = @json_decode(@file_get_contents($this->filepath), true);

if (false === $data) {
if (!is_array($data)) {
return null;
}

Expand Down

0 comments on commit 16152ae

Please sign in to comment.