Skip to content

Commit

Permalink
access token cached file path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aporat committed Dec 9, 2014
1 parent 5c87490 commit 01ed6c6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ReceiptValidator/GooglePlay/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ public function __construct(array $options = [])
$this->_client->setClientId($options['client_id']);
$this->_client->setClientSecret($options['client_secret']);

touch(sys_get_temp_dir() . '/googleplay_access_token.txt');
chmod(sys_get_temp_dir() . '/googleplay_access_token.txt', 0777);
$cached_access_token_path = sys_get_temp_dir() . '/' . 'googleplay_access_token_' . md5($options['client_id']) . '.txt';

touch($cached_access_token_path);
chmod($cached_access_token_path, 0777);

try {
$this->_client->setAccessToken(file_get_contents(sys_get_temp_dir() . '/googleplay_access_token.txt'));
$this->_client->setAccessToken(file_get_contents($cached_access_token_path));
} catch (\Exception $e) {
// skip exceptions when the access token is not valid
}

try {
if ($this->_client->isAccessTokenExpired()) {
$this->_client->refreshToken($options['refresh_token']);
file_put_contents(sys_get_temp_dir() . '/googleplay_access_token.txt', $this->_client->getAccessToken());
file_put_contents($cached_access_token_path, $this->_client->getAccessToken());
}
} catch (\Exception $e) {
throw new RuntimeException('Failed refreshing access token - ' . $e->getMessage());
Expand Down

0 comments on commit 01ed6c6

Please sign in to comment.