Commit 870a0e1e authored by dockx thibault's avatar dockx thibault
Browse files

Merge branch '41-integrator-web-service-call-requires-a-definition-of-an-http_agent' into 'dev'

Resolve "[Integrator] - Web Service call requires a definition of an HTTP_AGENT"

See merge request !50
2 merge requests!52:sparkles: Releasing Fusiondirectory Integrator 1.2,!50Resolve "[Integrator] - Web Service call requires a definition of an HTTP_AGENT"
Pipeline #31115 passed with stages
in 27 seconds
Showing with 15 additions and 0 deletions
+15 -0
......@@ -33,6 +33,11 @@ class WebServiceCall
{
$this->ch = !empty($URL) ? curl_init($URL) : curl_init($this->URL);
// We require to set a proper http_agent
$os = PHP_OS;
$phpVersion = PHP_VERSION;
$customUserAgent = "FusionDirectory/Integrator ($os; PHP $phpVersion; https://www.fusiondirectory.org) WebserviceLib";
// Manage a trick to perform refresh on user DN
if (!empty($data) && array_key_exists('refreshUser', $data)) {
// Empty array is required to update the user dn without passing information, json_encode will transform it to {}
......@@ -49,6 +54,7 @@ class WebServiceCall
case 'patch' :
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break;
case 'get' :
// No curl_setopt required
......@@ -56,13 +62,16 @@ class WebServiceCall
case 'put':
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break;
case 'delete':
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break;
case 'post':
curl_setopt($this->ch, CURLOPT_POST, TRUE);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break;
}
}
......@@ -103,9 +112,15 @@ class WebServiceCall
$ch = curl_init($this->URL);
// We require to set a proper http_agent
$os = PHP_OS;
$phpVersion = PHP_VERSION;
$customUserAgent = "FusionDirectory/Integrator ($os; PHP $phpVersion; https://www.fusiondirectory.org) WebserviceLib";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginData));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $customUserAgent);
$response = curl_exec($ch);
$this->handleCurlError($ch);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment