File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 21
21
"cakephp/cakephp" : " ^4.0" ,
22
22
"cakephp/cakephp-codesniffer" : " ^4.0" ,
23
23
"firebase/php-jwt" : " ^6.2" ,
24
- "phpunit/phpunit" : " ^8.5 || ^9.3"
24
+ "phpunit/phpunit" : " ^8.5 || ^9.3" ,
25
+ "symfony/cache" : " ^6.0"
25
26
},
26
27
"suggest" : {
27
28
"cakephp/orm" : " To use \" OrmResolver\" (Not needed separately if using full CakePHP framework)." ,
Original file line number Diff line number Diff line change 18
18
19
19
use ArrayObject ;
20
20
use Authentication \Identifier \IdentifierInterface ;
21
+ use Cake \Cache \Cache ;
22
+ use Cake \Http \Client ;
21
23
use Cake \Utility \Security ;
22
24
use Exception ;
25
+ use Firebase \JWT \CachedKeySet ;
23
26
use Firebase \JWT \JWK ;
24
27
use Firebase \JWT \JWT ;
25
28
use Firebase \JWT \Key ;
29
+ use Laminas \Diactoros \RequestFactory ;
26
30
use Psr \Http \Message \ServerRequestInterface ;
27
31
use RuntimeException ;
28
32
use stdClass ;
33
+ use Symfony \Component \Cache \Adapter \Psr16Adapter ;
29
34
30
35
class JwtAuthenticator extends TokenAuthenticator
31
36
{
@@ -41,6 +46,7 @@ class JwtAuthenticator extends TokenAuthenticator
41
46
'secretKey ' => null ,
42
47
'subjectKey ' => IdentifierInterface::CREDENTIAL_JWT_SUBJECT ,
43
48
'jwks ' => null ,
49
+ 'jwksCache ' => null ,
44
50
];
45
51
46
52
/**
@@ -149,7 +155,18 @@ protected function decodeToken(string $token): ?object
149
155
{
150
156
$ jsonWebKeySet = $ this ->getConfig ('jwks ' );
151
157
if ($ jsonWebKeySet ) {
152
- $ keySet = JWK ::parseKeySet ($ jsonWebKeySet );
158
+ $ jsonWebKeySetCache = $ this ->getConfig ('jwksCache ' );
159
+ if ($ jsonWebKeySetCache ) {
160
+ $ keySet = new CachedKeySet (
161
+ $ jsonWebKeySet ,
162
+ new Client (),
163
+ new RequestFactory (),
164
+ new Psr16Adapter (Cache::pool ($ jsonWebKeySetCache )),
165
+ 3000
166
+ );
167
+ } else {
168
+ $ keySet = JWK ::parseKeySet ($ jsonWebKeySet );
169
+ }
153
170
154
171
return JWT ::decode (
155
172
$ token ,
You can’t perform that action at this time.
0 commit comments