You are here

public function MoAuthApi::postCurlCall in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8

1 call to MoAuthApi::postCurlCall()
MoAuthApi::makeCurlCall in src/Api/MoAuthApi.php

File

src/Api/MoAuthApi.php, line 63

Class

MoAuthApi

Namespace

Drupal\miniorange_saml\Api

Code

public function postCurlCall($url, $fields, $http_header_array) {
  if (!Utilities::isCurlInstalled()) {
    return json_encode(array(
      "status" => 'CURL_ERROR',
      "statusMessage" => '<a href="http://php.net/manual/en/curl.installation.php">PHP cURL extension</a> is not installed or disabled.',
    ));
  }
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  # required for https urls
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header_array);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  $content = curl_exec($ch);
  if (curl_errno($ch)) {
    \Drupal::logger('miniorange_saml')
      ->notice('Error: ' . curl_error($ch) . ' in call of ' . $url);
  }
  curl_close($ch);
  return $content;
}