diff --git a/CHANGELOG.md b/CHANGELOG.md index be61f88..b277de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Yii Framework 2 authclient extension Change Log - Enh #387: Use appropriate exception if client does not exist (eluhr) - Enh #388: Added support to configure the OAuth2 access token location in requests and added a generic OAuth2 client (rhertogh) +- Enh #389: Added ability to configure OpenIdConnect cache duration, default is 1 week (viktorprogger) 2.2.15 December 16, 2023 @@ -276,6 +277,3 @@ Yii Framework 2 authclient extension Change Log ------------------------- - Initial release. - - - diff --git a/src/OpenIdConnect.php b/src/OpenIdConnect.php index 943e9b7..e0dcf61 100644 --- a/src/OpenIdConnect.php +++ b/src/OpenIdConnect.php @@ -160,6 +160,10 @@ class OpenIdConnect extends OAuth2 * @var JWKSet Key Set */ private $_jwkSet; + /** + * @var int cache duration in seconds, default: 1 week + */ + private $cacheDuration = 604800; /** @@ -218,13 +222,13 @@ public function getConfigParams() $cacheKey = $this->configParamsCacheKeyPrefix . $this->getId(); if ($cache === null || ($configParams = $cache->get($cacheKey)) === false) { $configParams = $this->discoverConfig(); + + if ($cache !== null) { + $cache->set($cacheKey, $configParams, $this->cacheDuration); + } } $this->_configParams = $configParams; - - if ($cache !== null) { - $cache->set($cacheKey, $configParams); - } } return $this->_configParams; } @@ -444,13 +448,13 @@ protected function getJwkSet() ->setUrl($this->getConfigParam('jwks_uri')); $response = $this->sendRequest($request); $jwkSet = JWKFactory::createFromValues($response); + + if ($cache !== null) { + $cache->set($cacheKey, $jwkSet, $this->cacheDuration); + } } $this->_jwkSet = $jwkSet; - - if ($cache !== null) { - $cache->set($cacheKey, $jwkSet); - } } return $this->_jwkSet; }