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 ...@@ -33,6 +33,11 @@ class WebServiceCall
{ {
$this->ch = !empty($URL) ? curl_init($URL) : curl_init($this->URL); $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 // Manage a trick to perform refresh on user DN
if (!empty($data) && array_key_exists('refreshUser', $data)) { 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 {} // Empty array is required to update the user dn without passing information, json_encode will transform it to {}
...@@ -49,6 +54,7 @@ class WebServiceCall ...@@ -49,6 +54,7 @@ class WebServiceCall
case 'patch' : case 'patch' :
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data)); curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break; break;
case 'get' : case 'get' :
// No curl_setopt required // No curl_setopt required
...@@ -56,13 +62,16 @@ class WebServiceCall ...@@ -56,13 +62,16 @@ class WebServiceCall
case 'put': case 'put':
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data)); curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break; break;
case 'delete': case 'delete':
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break; break;
case 'post': case 'post':
curl_setopt($this->ch, CURLOPT_POST, TRUE); curl_setopt($this->ch, CURLOPT_POST, TRUE);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data)); curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break; break;
} }
} }
...@@ -103,9 +112,15 @@ class WebServiceCall ...@@ -103,9 +112,15 @@ class WebServiceCall
$ch = curl_init($this->URL); $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_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginData)); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginData));
curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $customUserAgent);
$response = curl_exec($ch); $response = curl_exec($ch);
$this->handleCurlError($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