Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenIdConnect cache duration configuration option #389

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading