You are here

public static function MoAuthUtilities::callService in Google Authenticator / 2 Factor Authentication - 2FA 7

16 calls to MoAuthUtilities::callService()
AuthenticationAPIHandler::challenge in classes/AuthenticationAPIHandler.php
AuthenticationAPIHandler::getAuthStatus in classes/AuthenticationAPIHandler.php
AuthenticationAPIHandler::getGoogleAuthSecret in classes/AuthenticationAPIHandler.php
AuthenticationAPIHandler::getRegistrationStatus in classes/AuthenticationAPIHandler.php
AuthenticationAPIHandler::register in classes/AuthenticationAPIHandler.php

... See full list

File

classes/Utilities.php, line 251
This file is part of miniOrange 2FA module.

Class

MoAuthUtilities
@file This file is part of miniOrange 2FA module.

Code

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);

  // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  if (curl_errno($ch)) {
    return json_encode(array(
      "status" => 'CURL_ERROR',
      "message" => curl_errno($ch),
    ));
  }
  curl_close($ch);
  return json_decode($content);
}