Skip to content

Commit 98c73dc

Browse files
authored
updates auth and uses in-memory cache (#1019)
1 parent b9410f9 commit 98c73dc

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "Apache-2.0",
88
"require": {
99
"php": ">=5.4",
10-
"google/auth": "0.9",
10+
"google/auth": "0.10",
1111
"google/apiclient-services": "^0.6",
1212
"firebase/php-jwt": "~2.0|~3.0",
1313
"monolog/monolog": "^1.17",

src/Google/AccessToken/Verify.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpseclib\Crypt\RSA;
2323
use phpseclib\Math\BigInteger;
2424
use Psr\Cache\CacheItemPoolInterface;
25+
use Google\Auth\Cache\MemoryCacheItemPool;
2526
use Stash\Driver\FileSystem;
2627
use Stash\Pool;
2728

@@ -55,8 +56,12 @@ public function __construct(ClientInterface $http = null, CacheItemPoolInterface
5556
$http = new Client();
5657
}
5758

58-
if (is_null($cache) && class_exists('Stash\Pool')) {
59-
$cache = new Pool(new FileSystem);
59+
if (is_null($cache)) {
60+
if (class_exists('Stash\Pool')) {
61+
$cache = new Pool(new FileSystem);
62+
} else {
63+
$cache = new MemoryCacheItemPool;
64+
}
6065
}
6166

6267
$this->http = $http;

src/Google/Client.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
use Google\Auth\ApplicationDefaultCredentials;
19+
use Google\Auth\Cache\MemoryCacheItemPool;
1920
use Google\Auth\CredentialsLoader;
2021
use Google\Auth\HttpHandler\HttpHandlerFactory;
2122
use Google\Auth\OAuth2;
@@ -950,6 +951,10 @@ public function setCache(CacheItemPoolInterface $cache)
950951
*/
951952
public function getCache()
952953
{
954+
if (!$this->cache) {
955+
$this->cache = $this->createDefaultCache();
956+
}
957+
953958
return $this->cache;
954959
}
955960

@@ -990,6 +995,18 @@ protected function createDefaultLogger()
990995
return $logger;
991996
}
992997

998+
protected function createDefaultCache()
999+
{
1000+
// use filesystem cache by default if tedivm/stash exists
1001+
if (class_exists('Stash\Pool')) {
1002+
$cache = new Stash\Pool(new Stash\Driver\FileSystem);
1003+
} else {
1004+
$cache = new MemoryCacheItemPool;
1005+
}
1006+
1007+
return $cache;
1008+
}
1009+
9931010
/**
9941011
* Set the Http Client object
9951012
* @param GuzzleHttp\ClientInterface $http

0 commit comments

Comments
 (0)