@@ -36,28 +36,28 @@ class Keycloak extends AbstractOAuth2Base
3636 *
3737 * @return string
3838 */
39- public function getEndpoint (string $ endpoint )
39+ public function getDiscovery (string $ endpoint, $ default = '' )
4040 {
4141 if (!isset ($ this ->discovery )) {
4242 $ plugin = plugin_load ('helper ' , 'oauthkeycloak ' );
4343 $ json = file_get_contents ($ plugin ->getConf ('openidurl ' ));
4444 if (!$ json ) throw new \Exception ('Failed accessing ' . $ plugin ->getConf ('openidurl ' ));
4545 $ this ->discovery = json_decode ($ json , true );
4646 }
47- if (!isset ($ this ->discovery [$ endpoint ])) return '' ;
47+ if (!isset ($ this ->discovery [$ endpoint ])) return $ default ;
4848 return $ this ->discovery [$ endpoint ];
4949 }
5050
5151 /** @inheritdoc */
5252 public function getAuthorizationEndpoint ()
5353 {
54- return new Uri ($ this ->getEndpoint (self ::ENDPOINT_AUTH ));
54+ return new Uri ($ this ->getDiscovery (self ::ENDPOINT_AUTH ));
5555 }
5656
5757 /** @inheritdoc */
5858 public function getAccessTokenEndpoint ()
5959 {
60- return new Uri ($ this ->getEndpoint (self ::ENDPOINT_TOKEN ));
60+ return new Uri ($ this ->getDiscovery (self ::ENDPOINT_TOKEN ));
6161 }
6262
6363 /** @inheritdoc */
@@ -72,6 +72,18 @@ public function needsStateParameterInAuthUrl()
7272 return true ;
7373 }
7474
75+ /** @inheritdoc */
76+ public function getCodeChallengeMethod ()
77+ {
78+ $ methods = $ this ->getDiscovery ('code_challenge_methods_supported ' , []);
79+ foreach (['S256 ' , 'plain ' ] as $ m ) {
80+ if (in_array ($ m , $ methods )) {
81+ return $ m ;
82+ }
83+ }
84+ return null ;
85+ }
86+
7587 /**
7688 * Logout from Keycloak
7789 *
@@ -94,7 +106,7 @@ public function logout()
94106 ];
95107
96108 $ this ->httpClient ->retrieveResponse (
97- new Uri ($ this ->getEndpoint (self ::ENDPOINT_LOGOUT )),
109+ new Uri ($ this ->getDiscovery (self ::ENDPOINT_LOGOUT )),
98110 $ parameters ,
99111 $ this ->getExtraOAuthHeaders ()
100112 );
0 commit comments