@@ -6735,6 +6735,21 @@ protected function getArrayProperty(string $key, string $default): array
67356735 return array_filter (array_map ('trim ' , explode (', ' , $ this ->getProperty ($ key , $ default ))));
67366736 }
67376737
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+
67386753 protected function getProperty (string $ key , $ default )
67396754 {
67406755 return isset ($ this ->properties [$ key ]) ? $ this ->properties [$ key ] : $ default ;
@@ -7582,7 +7597,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
75827597
75837598 class JwtAuthMiddleware extends Middleware
75847599 {
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
75867601 {
75877602 $ algorithms = array (
75887603 'HS256 ' => 'sha256 ' ,
@@ -7597,9 +7612,14 @@ private function getVerifiedClaims(string $token, int $time, int $leeway, int $t
75977612 return array ();
75987613 }
75997614 $ 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 ]) {
76017620 return array ();
76027621 }
7622+ $ secret = $ secrets [$ kid ];
76037623 if ($ header ['typ ' ] != 'JWT ' ) {
76047624 return array ();
76057625 }
@@ -7663,16 +7683,16 @@ private function getClaims(string $token): array
76637683 $ time = (int ) $ this ->getProperty ('time ' , time ());
76647684 $ leeway = (int ) $ this ->getProperty ('leeway ' , '5 ' );
76657685 $ ttl = (int ) $ this ->getProperty ('ttl ' , '30 ' );
7666- $ secret = $ this ->getProperty ( ' secret ' , '' );
7686+ $ secrets = $ this ->getMapProperty ( ' secrets ' , '' );
76677687 $ requirements = array (
76687688 'alg ' => $ this ->getArrayProperty ('algorithms ' , '' ),
76697689 'aud ' => $ this ->getArrayProperty ('audiences ' , '' ),
76707690 'iss ' => $ this ->getArrayProperty ('issuers ' , '' ),
76717691 );
7672- if (!$ secret ) {
7692+ if (!$ secrets ) {
76737693 return array ();
76747694 }
7675- return $ this ->getVerifiedClaims ($ token , $ time , $ leeway , $ ttl , $ secret , $ requirements );
7695+ return $ this ->getVerifiedClaims ($ token , $ time , $ leeway , $ ttl , $ secrets , $ requirements );
76767696 }
76777697
76787698 private function getAuthorizationToken (ServerRequestInterface $ request ): string
0 commit comments