@@ -17,6 +17,7 @@ class OpenIdVerificator
1717
1818 private $ guzzle ;
1919 private $ rsa ;
20+ private $ maxAge = [];
2021
2122 public function __construct (Client $ guzzle , RSA $ rsa )
2223 {
@@ -26,9 +27,12 @@ public function __construct(Client $guzzle, RSA $rsa)
2627
2728 public function getPublicKey ($ kid = null )
2829 {
29- $ v3Certs = Cache::rememberForever (self ::V3_CERTS , function () {
30- return $ this ->getv3Certs ();
31- });
30+ if (Cache::has (self ::V3_CERTS )) {
31+ $ v3Certs = Cache::get (self ::V3_CERTS );
32+ } else {
33+ $ v3Certs = $ this ->getv3Certs ();
34+ Cache::put (self ::V3_CERTS , $ v3Certs , $ this ->maxAge [self ::URL_OPENID_CONFIG ]);
35+ }
3236
3337 $ cert = $ kid ? collect ($ v3Certs )->firstWhere ('kid ' , '= ' , $ kid ) : $ v3Certs [0 ];
3438
@@ -63,6 +67,14 @@ private function callApiAndReturnValue($url, $value)
6367
6468 $ data = json_decode ($ response ->getBody (), true );
6569
70+ $ maxAge = 0 ;
71+ foreach ($ response ->getHeader ('Cache-Control ' ) as $ line ) {
72+ preg_match ('/max-age=(\d+)/ ' , $ line , $ matches );
73+ $ maxAge = isset ($ matches [1 ]) ? (int ) $ matches [1 ] : 0 ;
74+ }
75+
76+ $ this ->maxAge [$ url ] = $ maxAge ;
77+
6678 return Arr::get ($ data , $ value );
6779 }
6880
0 commit comments