File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -60,8 +60,11 @@ protected function loadFromPath(string $path)
6060 */
6161 protected function loadFromJwkArray (array $ jwk )
6262 {
63- if ($ jwk ['alg ' ] !== 'RS256 ' ) {
64- throw new OidcInvalidKeyException ("Only RS256 keys are currently supported. Found key using {$ jwk ['alg ' ]}" );
63+ // 'alg' is optional for a JWK, but we will still attempt to validate if
64+ // it exists otherwise presume it will be compatible.
65+ $ alg = $ jwk ['alg ' ] ?? null ;
66+ if ($ jwk ['kty ' ] !== 'RSA ' || !(is_null ($ alg ) || $ alg === 'RS256 ' )) {
67+ throw new OidcInvalidKeyException ("Only RS256 keys are currently supported. Found key using {$ alg }" );
6568 }
6669
6770 if (empty ($ jwk ['use ' ])) {
Original file line number Diff line number Diff line change @@ -164,7 +164,8 @@ protected function loadSettingsFromIssuerDiscovery(ClientInterface $httpClient):
164164 protected function filterKeys (array $ keys ): array
165165 {
166166 return array_filter ($ keys , function (array $ key ) {
167- return $ key ['kty ' ] === 'RSA ' && $ key ['use ' ] === 'sig ' && $ key ['alg ' ] === 'RS256 ' ;
167+ $ alg = $ key ['alg ' ] ?? null ;
168+ return $ key ['kty ' ] === 'RSA ' && $ key ['use ' ] === 'sig ' && (is_null ($ alg ) || $ alg === 'RS256 ' );
168169 });
169170 }
170171
Original file line number Diff line number Diff line change @@ -318,6 +318,31 @@ public function test_autodiscovery_calls_are_cached()
318318 $ this ->assertCount (4 , $ transactions );
319319 }
320320
321+ public function test_auth_login_with_autodiscovery_with_keys_that_do_not_have_alg_property ()
322+ {
323+ $ this ->withAutodiscovery ();
324+
325+ $ keyArray = OidcJwtHelper::publicJwkKeyArray ();
326+ unset($ keyArray ['alg ' ]);
327+
328+ $ this ->mockHttpClient ([
329+ $ this ->getAutoDiscoveryResponse (),
330+ new Response (200 , [
331+ 'Content-Type ' => 'application/json ' ,
332+ 'Cache-Control ' => 'no-cache, no-store ' ,
333+ 'Pragma ' => 'no-cache ' ,
334+ ], json_encode ([
335+ 'keys ' => [
336+ $ keyArray ,
337+ ],
338+ ])),
339+ ]);
340+
341+ $ this ->assertFalse (auth ()->check ());
342+ $ this ->runLogin ();
343+ $ this ->assertTrue (auth ()->check ());
344+ }
345+
321346 protected function withAutodiscovery ()
322347 {
323348 config ()->set ([
You can’t perform that action at this time.
0 commit comments