@@ -6735,6 +6735,21 @@ protected function getArrayProperty(string $key, string $default): array
6735
6735
return array_filter (array_map ('trim ' , explode (', ' , $ this ->getProperty ($ key , $ default ))));
6736
6736
}
6737
6737
6738
+ protected function getMapProperty (string $ key , string $ default ): array
6739
+ {
6740
+ $ pairs = $ this ->getArrayProperty ($ key , $ default );
6741
+ $ result = array ();
6742
+ foreach ($ pairs as $ pair ) {
6743
+ if (strpos ($ pair , ': ' )) {
6744
+ list ($ k , $ v ) = explode (': ' , $ pair , 2 );
6745
+ $ result [trim ($ k )] = trim ($ v );
6746
+ } else {
6747
+ $ result [] = trim ($ pair );
6748
+ }
6749
+ }
6750
+ return $ result ;
6751
+ }
6752
+
6738
6753
protected function getProperty (string $ key , $ default )
6739
6754
{
6740
6755
return isset ($ this ->properties [$ key ]) ? $ this ->properties [$ key ] : $ default ;
@@ -7582,7 +7597,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7582
7597
7583
7598
class JwtAuthMiddleware extends Middleware
7584
7599
{
7585
- private function getVerifiedClaims (string $ token , int $ time , int $ leeway , int $ ttl , string $ secret , array $ requirements ): array
7600
+ private function getVerifiedClaims (string $ token , int $ time , int $ leeway , int $ ttl , array $ secrets , array $ requirements ): array
7586
7601
{
7587
7602
$ algorithms = array (
7588
7603
'HS256 ' => 'sha256 ' ,
@@ -7597,9 +7612,14 @@ private function getVerifiedClaims(string $token, int $time, int $leeway, int $t
7597
7612
return array ();
7598
7613
}
7599
7614
$ header = json_decode (base64_decode (strtr ($ token [0 ], '-_ ' , '+/ ' )), true );
7600
- if (!$ secret ) {
7615
+ $ kid = 0 ;
7616
+ if (isset ($ header ['kid ' ])) {
7617
+ $ kid = $ header ['kid ' ];
7618
+ }
7619
+ if (!$ secrets [$ kid ]) {
7601
7620
return array ();
7602
7621
}
7622
+ $ secret = $ secrets [$ kid ];
7603
7623
if ($ header ['typ ' ] != 'JWT ' ) {
7604
7624
return array ();
7605
7625
}
@@ -7663,16 +7683,16 @@ private function getClaims(string $token): array
7663
7683
$ time = (int ) $ this ->getProperty ('time ' , time ());
7664
7684
$ leeway = (int ) $ this ->getProperty ('leeway ' , '5 ' );
7665
7685
$ ttl = (int ) $ this ->getProperty ('ttl ' , '30 ' );
7666
- $ secret = $ this ->getProperty ( ' secret ' , '' );
7686
+ $ secrets = $ this ->getMapProperty ( ' secrets ' , '' );
7667
7687
$ requirements = array (
7668
7688
'alg ' => $ this ->getArrayProperty ('algorithms ' , '' ),
7669
7689
'aud ' => $ this ->getArrayProperty ('audiences ' , '' ),
7670
7690
'iss ' => $ this ->getArrayProperty ('issuers ' , '' ),
7671
7691
);
7672
- if (!$ secret ) {
7692
+ if (!$ secrets ) {
7673
7693
return array ();
7674
7694
}
7675
- return $ this ->getVerifiedClaims ($ token , $ time , $ leeway , $ ttl , $ secret , $ requirements );
7695
+ return $ this ->getVerifiedClaims ($ token , $ time , $ leeway , $ ttl , $ secrets , $ requirements );
7676
7696
}
7677
7697
7678
7698
private function getAuthorizationToken (ServerRequestInterface $ request ): string
0 commit comments