From 1fbf215e5c2f101856cc567ce1824812d4af0fb4 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Thu, 9 May 2024 19:14:31 +0500 Subject: [PATCH 1/2] Add OpenIdConnect cache duration configuration option --- CHANGELOG.md | 4 +--- src/OpenIdConnect.php | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be61f88..dc5f5d5 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 #x: Added ability to configure OpenIdConnect cache duration. Default is 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; } From 47b958523a30d685e759345687ee1f6c7379e2e7 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Thu, 9 May 2024 19:18:53 +0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc5f5d5..b277de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +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 #x: Added ability to configure OpenIdConnect cache duration. Default is +- Enh #389: Added ability to configure OpenIdConnect cache duration, default is 1 week (viktorprogger) 2.2.15 December 16, 2023