Skip to content

Commit 879c5f1

Browse files
Fix #389: Added ability to configure OpenIdConnect cache duration, default is 1 week
1 parent b9f753f commit 879c5f1

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Yii Framework 2 authclient extension Change Log
66

77
- Enh #387: Use appropriate exception if client does not exist (eluhr)
88
- Enh #388: Added support to configure the OAuth2 access token location in requests and added a generic OAuth2 client (rhertogh)
9+
- Enh #389: Added ability to configure OpenIdConnect cache duration, default is 1 week (viktorprogger)
910

1011

1112
2.2.15 December 16, 2023
@@ -276,6 +277,3 @@ Yii Framework 2 authclient extension Change Log
276277
-------------------------
277278

278279
- Initial release.
279-
280-
281-

src/OpenIdConnect.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ class OpenIdConnect extends OAuth2
160160
* @var JWKSet Key Set
161161
*/
162162
private $_jwkSet;
163+
/**
164+
* @var int cache duration in seconds, default: 1 week
165+
*/
166+
private $cacheDuration = 604800;
163167

164168

165169
/**
@@ -218,13 +222,13 @@ public function getConfigParams()
218222
$cacheKey = $this->configParamsCacheKeyPrefix . $this->getId();
219223
if ($cache === null || ($configParams = $cache->get($cacheKey)) === false) {
220224
$configParams = $this->discoverConfig();
225+
226+
if ($cache !== null) {
227+
$cache->set($cacheKey, $configParams, $this->cacheDuration);
228+
}
221229
}
222230

223231
$this->_configParams = $configParams;
224-
225-
if ($cache !== null) {
226-
$cache->set($cacheKey, $configParams);
227-
}
228232
}
229233
return $this->_configParams;
230234
}
@@ -444,13 +448,13 @@ protected function getJwkSet()
444448
->setUrl($this->getConfigParam('jwks_uri'));
445449
$response = $this->sendRequest($request);
446450
$jwkSet = JWKFactory::createFromValues($response);
451+
452+
if ($cache !== null) {
453+
$cache->set($cacheKey, $jwkSet, $this->cacheDuration);
454+
}
447455
}
448456

449457
$this->_jwkSet = $jwkSet;
450-
451-
if ($cache !== null) {
452-
$cache->set($cacheKey, $jwkSet);
453-
}
454458
}
455459
return $this->_jwkSet;
456460
}

0 commit comments

Comments
 (0)