public static function MoAuthUtilities::callService in Google Authenticator / 2 Factor Authentication - 2FA 8
Same name and namespace in other branches
- 8.2 src/MoAuthUtilities.php \Drupal\miniorange_2fa\MoAuthUtilities::callService()
16 calls to MoAuthUtilities::callService()
- AuthenticationAPIHandler::challenge in src/
AuthenticationAPIHandler.php - AuthenticationAPIHandler::getAuthStatus in src/
AuthenticationAPIHandler.php - AuthenticationAPIHandler::getGoogleAuthSecret in src/
AuthenticationAPIHandler.php - AuthenticationAPIHandler::getRegistrationStatus in src/
AuthenticationAPIHandler.php - AuthenticationAPIHandler::register in src/
AuthenticationAPIHandler.php
File
- src/
MoAuthUtilities.php, line 286 - This file is part of miniOrange 2FA module.
Class
Namespace
Drupal\miniorange_2faCode
public static function callService($customer_id, $apiKey, $url, $json) {
if (!self::isCurlInstalled()) {
return json_encode(array(
"status" => 'CURL_ERROR',
"message" => 'PHP cURL extension is not installed or disabled.',
));
}
$ch = curl_init($url);
$current_time_in_millis = round(microtime(TRUE) * 1000);
$string_to_hash = $customer_id . number_format($current_time_in_millis, 0, '', '') . $apiKey;
$hash_value = hash("sha512", $string_to_hash);
$customer_key_header = "Customer-Key: " . $customer_id;
$timestamp_header = "Timestamp: " . number_format($current_time_in_millis, 0, '', '');
$authorization_header = "Authorization: " . $hash_value;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
// Required for https urls.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
$customer_key_header,
$timestamp_header,
$authorization_header,
));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$content = curl_exec($ch);
if (curl_errno($ch)) {
return json_encode(array(
"status" => 'CURL_ERROR',
"message" => curl_errno($ch),
));
}
curl_close($ch);
return json_decode($content);
}