Skip to content

Commit

Permalink
Fix #389: Added ability to configure OpenIdConnect cache duration, de…
Browse files Browse the repository at this point in the history
…fault is 1 week
  • Loading branch information
viktorprogger committed May 10, 2024
1 parent b9f753f commit 879c5f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,6 +277,3 @@ Yii Framework 2 authclient extension Change Log
-------------------------

- Initial release.



20 changes: 12 additions & 8 deletions src/OpenIdConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 879c5f1

Please sign in to comment.