@@ -29,31 +29,35 @@ class Keycloak extends AbstractOAuth2Base
2929 */
3030 const ENDPOINT_LOGOUT = 'end_session_endpoint ' ;
3131
32+ protected $ discovery ;
33+
3234 /**
3335 * Return URI of discovered endpoint
3436 *
3537 * @return string
3638 */
37- public static function getEndpointUri (string $ endpoint )
39+ public function getEndpoint (string $ endpoint )
3840 {
39- $ plugin = plugin_load ('helper ' , 'oauthkeycloak ' );
40- $ json = file_get_contents ($ plugin ->getConf ('openidurl ' ));
41- if (!$ json ) return '' ;
42- $ data = json_decode ($ json , true );
43- if (!isset ($ data [$ endpoint ])) return '' ;
44- return $ data [$ endpoint ];
41+ if (!isset ($ this ->discovery )) {
42+ $ plugin = plugin_load ('helper ' , 'oauthkeycloak ' );
43+ $ json = file_get_contents ($ plugin ->getConf ('openidurl ' ));
44+ if (!$ json ) return '' ;
45+ $ this ->discovery = json_decode ($ json , true );
46+ }
47+ if (!isset ($ this ->discovery [$ endpoint ])) return '' ;
48+ return $ this ->discovery [$ endpoint ];
4549 }
4650
4751 /** @inheritdoc */
4852 public function getAuthorizationEndpoint ()
4953 {
50- return new Uri (self :: getEndpointUri (self ::ENDPOINT_AUTH ));
54+ return new Uri ($ this -> getEndpoint (self ::ENDPOINT_AUTH ));
5155 }
5256
5357 /** @inheritdoc */
5458 public function getAccessTokenEndpoint ()
5559 {
56- return new Uri (self :: getEndpointUri (self ::ENDPOINT_TOKEN ));
60+ return new Uri ($ this -> getEndpoint (self ::ENDPOINT_TOKEN ));
5761 }
5862
5963 /** @inheritdoc */
@@ -84,7 +88,7 @@ public function logout()
8488 ];
8589
8690 $ this ->httpClient ->retrieveResponse (
87- new Uri (self :: getEndpointUri (self ::ENDPOINT_LOGOUT )),
91+ new Uri ($ this -> getEndpoint (self ::ENDPOINT_LOGOUT )),
8892 $ parameters ,
8993 $ this ->getExtraOAuthHeaders ()
9094 );
0 commit comments