@@ -261,6 +261,11 @@ class OpenIDConnectClient
261261 */
262262 private $ backChannelSubject ;
263263
264+ /**
265+ * @var array list of supported auth methods
266+ */
267+ private $ token_endpoint_auth_methods_supported = ['client_secret_basic ' ];
268+
264269 /**
265270 * @param $provider_url string optional
266271 *
@@ -597,6 +602,14 @@ public function addRegistrationParam($param) {
597602 $ this ->registrationParams = array_merge ($ this ->registrationParams , (array )$ param );
598603 }
599604
605+ /**
606+ * @param array $token_endpoint_auth_methods_supported
607+ */
608+ public function setTokenEndpointAuthMethodsSupported ($ token_endpoint_auth_methods_supported )
609+ {
610+ $ this ->token_endpoint_auth_methods_supported = $ token_endpoint_auth_methods_supported ;
611+ }
612+
600613 /**
601614 * @param $jwk object - example: (object) ['kid' => ..., 'nbf' => ..., 'use' => 'sig', 'kty' => "RSA", 'e' => "", 'n' => ""]
602615 */
@@ -872,7 +885,7 @@ public function requestResourceOwnerToken($bClientAuth = FALSE) {
872885 //For client authentication include the client values
873886 if ($ bClientAuth ) {
874887 $ token_endpoint_auth_methods_supported = $ this ->getProviderConfigValue ('token_endpoint_auth_methods_supported ' , ['client_secret_basic ' ]);
875- if (in_array ('client_secret_basic ' , $ token_endpoint_auth_methods_supported, true )) {
888+ if ($ this -> supportsAuthMethod ('client_secret_basic ' , $ token_endpoint_auth_methods_supported )) {
876889 $ headers = ['Authorization: Basic ' . base64_encode (urlencode ($ this ->clientID ) . ': ' . urlencode ($ this ->clientSecret ))];
877890 } else {
878891 $ post_data ['client_id ' ] = $ this ->clientID ;
@@ -911,19 +924,19 @@ protected function requestTokens($code, $headers = array()) {
911924
912925 $ authorizationHeader = null ;
913926 # Consider Basic authentication if provider config is set this way
914- if (in_array ('client_secret_basic ' , $ token_endpoint_auth_methods_supported, true )) {
927+ if ($ this -> supportsAuthMethod ('client_secret_basic ' , $ token_endpoint_auth_methods_supported )) {
915928 $ authorizationHeader = 'Authorization: Basic ' . base64_encode (urlencode ($ this ->clientID ) . ': ' . urlencode ($ this ->clientSecret ));
916929 unset($ token_params ['client_secret ' ]);
917930 unset($ token_params ['client_id ' ]);
918931 }
919932
920933 // When there is a private key jwt generator and it is supported then use it as client authentication
921- if ($ this ->privateKeyJwtGenerator !== null && in_array ('private_key_jwt ' , $ token_endpoint_auth_methods_supported, true )) {
934+ if ($ this ->privateKeyJwtGenerator !== null && $ this -> supportsAuthMethod ('private_key_jwt ' , $ token_endpoint_auth_methods_supported )) {
922935 $ token_params ['client_assertion_type ' ] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer ' ;
923936 $ token_params ['client_assertion ' ] = $ this ->privateKeyJwtGenerator ->__invoke ($ token_endpoint );
924937 }
925938
926- if (in_array ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported, true )) {
939+ if ($ this -> supportsAuthMethod ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported )) {
927940 $ client_assertion_type = $ this ->getProviderConfigValue ('client_assertion_type ' );
928941
929942 if (isset ($ this ->providerConfig ['client_assertion ' ])){
@@ -994,7 +1007,7 @@ public function requestTokenExchange($subjectToken, $subjectTokenType, $audience
9941007 }
9951008
9961009 # Consider Basic authentication if provider config is set this way
997- if (in_array ('client_secret_basic ' , $ token_endpoint_auth_methods_supported, true )) {
1010+ if ($ this -> supportsAuthMethod ('client_secret_basic ' , $ token_endpoint_auth_methods_supported )) {
9981011 $ headers = ['Authorization: Basic ' . base64_encode (urlencode ($ this ->clientID ) . ': ' . urlencode ($ this ->clientSecret ))];
9991012 unset($ post_data ['client_secret ' ]);
10001013 unset($ post_data ['client_id ' ]);
@@ -1031,13 +1044,13 @@ public function refreshToken($refresh_token) {
10311044 ];
10321045
10331046 # Consider Basic authentication if provider config is set this way
1034- if (in_array ('client_secret_basic ' , $ token_endpoint_auth_methods_supported, true )) {
1047+ if ($ this -> supportsAuthMethod ('client_secret_basic ' , $ token_endpoint_auth_methods_supported )) {
10351048 $ headers = ['Authorization: Basic ' . base64_encode (urlencode ($ this ->clientID ) . ': ' . urlencode ($ this ->clientSecret ))];
10361049 unset($ token_params ['client_secret ' ]);
10371050 unset($ token_params ['client_id ' ]);
10381051 }
10391052
1040- if (in_array ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported, true )) {
1053+ if ($ this -> supportsAuthMethod ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported )) {
10411054 $ client_assertion_type = $ this ->getProviderConfigValue ('client_assertion_type ' );
10421055 $ client_assertion = $ this ->getJWTClientAssertion ($ this ->getProviderConfigValue ('token_endpoint ' ));
10431056
@@ -1728,7 +1741,7 @@ public function introspectToken($token, $token_type_hint = '', $clientId = null,
17281741 $ headers = ['Authorization: Basic ' . base64_encode (urlencode ($ clientId ) . ': ' . urlencode ($ clientSecret )),
17291742 'Accept: application/json ' ];
17301743
1731- if (in_array ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported, true )) {
1744+ if ($ this -> supportsAuthMethod ('client_secret_jwt ' , $ token_endpoint_auth_methods_supported )) {
17321745 $ client_assertion_type = $ this ->getProviderConfigValue ('client_assertion_type ' );
17331746 $ client_assertion = $ this ->getJWTClientAssertion ($ this ->getProviderConfigValue ('introspection_endpoint ' ));
17341747
@@ -2188,4 +2201,19 @@ public function getSidFromBackChannel() {
21882201 public function getSubjectFromBackChannel () {
21892202 return $ this ->backChannelSubject ;
21902203 }
2204+
2205+ /**
2206+ * @param string $auth_method
2207+ * @param array $token_endpoint_auth_methods_supported
2208+ * @return bool
2209+ */
2210+ public function supportsAuthMethod ($ auth_method , $ token_endpoint_auth_methods_supported )
2211+ {
2212+ # client_secret_jwt has to explicitly be enabled
2213+ if (!in_array ($ auth_method , $ this ->token_endpoint_auth_methods_supported , true )) {
2214+ return false ;
2215+ }
2216+
2217+ return in_array ($ auth_method , $ token_endpoint_auth_methods_supported , true );
2218+ }
21912219}
0 commit comments