Skip to content

Commit e28ab77

Browse files
committed
use client_secret_basic on refreshToken() and requestClientCredentialsToken() if supported
1 parent 24a4ee0 commit e28ab77

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.1.2]
8+
9+
### Changed
10+
* algorithm to determine if `client_secret_basic` or `client_secret_post` will be used for authentication in `refreshToken()` and `requestClientCredentialsToken()` is now the same like in `requestTokens()`
11+
712
## [1.1.1]
813

914
### Changed

src/OpenIDConnectClient.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ private function requestAuthorization() {
728728
*/
729729
public function requestClientCredentialsToken() {
730730
$token_endpoint = $this->getProviderConfigValue('token_endpoint');
731+
$token_endpoint_auth_methods_supported = $this->getProviderConfigValue('token_endpoint_auth_methods_supported', ['client_secret_basic']);
731732

732733
$headers = [];
733734

@@ -740,6 +741,13 @@ public function requestClientCredentialsToken() {
740741
'scope' => implode(' ', $this->scopes)
741742
];
742743

744+
// Consider Basic authentication if provider config is set this way
745+
if (in_array('client_secret_basic', $token_endpoint_auth_methods_supported, true)) {
746+
$headers = ['Authorization: Basic ' . base64_encode(urlencode($this->clientID) . ':' . urlencode($this->clientSecret))];
747+
unset($post_data['client_secret']);
748+
unset($post_data['client_id']);
749+
}
750+
743751
// Convert token params to string format
744752
$post_params = http_build_query($post_data, '', '&', $this->encType);
745753

@@ -840,6 +848,9 @@ protected function requestTokens($code) {
840848
*/
841849
public function refreshToken($refresh_token, $sendScopes = true) {
842850
$token_endpoint = $this->getProviderConfigValue('token_endpoint');
851+
$token_endpoint_auth_methods_supported = $this->getProviderConfigValue('token_endpoint_auth_methods_supported', ['client_secret_basic']);
852+
853+
$headers = [];
843854

844855
$grant_type = 'refresh_token';
845856

@@ -854,10 +865,17 @@ public function refreshToken($refresh_token, $sendScopes = true) {
854865
$token_params['scopes'] = implode(' ', $this->scopes);
855866
}
856867

868+
// Consider Basic authentication if provider config is set this way
869+
if (in_array('client_secret_basic', $token_endpoint_auth_methods_supported, true)) {
870+
$headers = ['Authorization: Basic ' . base64_encode(urlencode($this->clientID) . ':' . urlencode($this->clientSecret))];
871+
unset($token_params['client_secret']);
872+
unset($token_params['client_id']);
873+
}
874+
857875
// Convert token params to string format
858876
$token_params = http_build_query($token_params, '', '&', $this->encType);
859877

860-
$json = json_decode($this->fetchURL($token_endpoint, $token_params));
878+
$json = json_decode($this->fetchURL($token_endpoint, $token_params, $headers));
861879

862880
if (isset($json->access_token)) {
863881
$this->accessToken = $json->access_token;

0 commit comments

Comments
 (0)