File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
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 \Utility \Hash ;
21
+ use Cake \Cache \Cache ;
22
+ use Cake \Http \Client ;
22
23
use Cake \Utility \Security ;
23
24
use Exception ;
25
+ use Firebase \JWT \CachedKeySet ;
24
26
use Firebase \JWT \JWK ;
25
27
use Firebase \JWT \JWT ;
26
28
use Firebase \JWT \Key ;
29
+ use Laminas \Diactoros \RequestFactory ;
27
30
use Psr \Http \Message \ServerRequestInterface ;
28
31
use RuntimeException ;
29
32
use stdClass ;
33
+ use Symfony \Component \Cache \Adapter \Psr16Adapter ;
30
34
31
35
class JwtAuthenticator extends TokenAuthenticator
32
36
{
@@ -42,6 +46,7 @@ class JwtAuthenticator extends TokenAuthenticator
42
46
'secretKey ' => null ,
43
47
'subjectKey ' => IdentifierInterface::CREDENTIAL_JWT_SUBJECT ,
44
48
'jwks ' => null ,
49
+ 'jwksCache ' => null ,
45
50
];
46
51
47
52
/**
@@ -150,7 +155,18 @@ protected function decodeToken(string $token): ?object
150
155
{
151
156
$ jsonWebKeySet = $ this ->getConfig ('jwks ' );
152
157
if ($ jsonWebKeySet ) {
153
- $ 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
+ }
154
170
155
171
return JWT ::decode (
156
172
$ token ,
You can’t perform that action at this time.
0 commit comments