diff --git a/CHANGELOG.md b/CHANGELOG.md index 68264e32..81f127d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [unreleased] +* User-Agent is set for any HTTP method in fetchURL() (not just POST). #382 * Update visibility of getWellKnownConfigValue to protected. #363 * Fixed issue on authentication for php8. #354 * Support for signed and encrypted UserInfo response. #305 diff --git a/src/OpenIDConnectClient.php b/src/OpenIDConnectClient.php index c0015c83..6aa80b17 100644 --- a/src/OpenIDConnectClient.php +++ b/src/OpenIDConnectClient.php @@ -1367,7 +1367,6 @@ protected function fetchURL(string $url, string $post_body = null, array $header // Allows to keep the POST method even after redirect curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body); - curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent()); // Default content type is form encoded $content_type = 'application/x-www-form-urlencoded'; @@ -1381,6 +1380,9 @@ protected function fetchURL(string $url, string $post_body = null, array $header $headers[] = "Content-Type: $content_type"; } + // Set the User-Agent + curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent()); + // If we set some headers include them if(count($headers) > 0) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);