static function generateTelesignHeaders (
    $customer_id,
    $api_key,
    $method_name,
    $resource,
    $url_encoded_fields,
    $date = null,
    $nonce = null,
    $user_agent = null,
    $content_type = null
  ) {
    if (!$date) {
      $date = gmdate("D, d M Y H:i:s T");
    }

    if (!$nonce) {
      $nonce = Uuid::uuid4()->toString();
    }
    
    if (!$content_type) {
        $content_type = in_array($method_name, ["POST", "PUT"]) ? "application/x-www-form-urlencoded" : "";
    }
    
    $auth_method = "HMAC-SHA256";

    $string_to_sign_builder = [
      $method_name,
      "\n$content_type",
      "\n$date",
      "\nx-ts-auth-method:$auth_method",
      "\nx-ts-nonce:$nonce"
    ];

    if ($content_type && $url_encoded_fields) {
      $string_to_sign_builder[] = "\n$url_encoded_fields";
    }

    $string_to_sign_builder[] = "\n$resource";

    $string_to_sign = join("", $string_to_sign_builder);

    $signature = base64_encode(
      hash_hmac("sha256", utf8_encode($string_to_sign), base64_decode($api_key), true)
    );
    $authorization = "TSA $customer_id:$signature";

    $headers = [
      "Authorization" => $authorization,
      "Date" => $date,
      "Content-Type" => $content_type,
      "x-ts-auth-method" => $auth_method,
      "x-ts-nonce" => $nonce
    ];

    if ($user_agent) {
      $headers["User-Agent"] = $user_agent;
    }

    return $headers;
  }
static function generateTelesignHeaders (
    $customer_id,
    $api_key,
    $method_name,
    $resource,
    $url_encoded_fields,
    $date = null,
    $nonce = null,
    $user_agent = null,
    $content_type = null
  ) {
    if (!$date) {
      $date = gmdate("D, d M Y H:i:s T");
    }

    if (!$nonce) {
      $nonce = Uuid::uuid4()->toString();
    }
    
    if (!$content_type) {
        $content_type = in_array($method_name, ["POST", "PUT"]) ? "application/x-www-form-urlencoded" : "";
    }
    
    $auth_method = "HMAC-SHA256";

    $string_to_sign_builder = [
      $method_name,
      "\n$content_type",
      "\n$date",
      "\nx-ts-auth-method:$auth_method",
      "\nx-ts-nonce:$nonce"
    ];

    if ($content_type && $url_encoded_fields) {
      $string_to_sign_builder[] = "\n$url_encoded_fields";
    }

    $string_to_sign_builder[] = "\n$resource";

    $string_to_sign = join("", $string_to_sign_builder);

    $signature = base64_encode(
      hash_hmac("sha256", utf8_encode($string_to_sign), base64_decode($api_key), true)
    );
    $authorization = "TSA $customer_id:$signature";

    $headers = [
      "Authorization" => $authorization,
      "Date" => $date,
      "Content-Type" => $content_type,
      "x-ts-auth-method" => $auth_method,
      "x-ts-nonce" => $nonce
    ];

    if ($user_agent) {
      $headers["User-Agent"] = $user_agent;
    }

    return $headers;
  }
static function generateTelesignHeaders ( $ customer_id , $ api_key , $ method_name , $ resource , $ url_encoded_fields , $ date = null , $ nonce = null , $ user_agent = null , $ content_type = null ) { if ( ! $ date ) { $ date = gmdate ( "D, d M Y H:i:s T" ) ; } if ( ! $ nonce ) { $ nonce = Uuid :: uuid4 ( ) -> toString ( ) ; } if ( ! $ content_type ) { $ content_type = in_array ( $ method_name , [ "POST" , "PUT" ] ) ? "application/x-www-form-urlencoded" : "" ; } $ auth_method = "HMAC-SHA256" ; $ string_to_sign_builder = [ $ method_name , "\n$content_type" , "\n$date" , "\nx-ts-auth-method:$auth_method" , "\nx-ts-nonce:$nonce" ] ; if ( $ content_type && $ url_encoded_fields ) { $ string_to_sign_builder [ ] = "\n$url_encoded_fields" ; } $ string_to_sign_builder [ ] = "\n$resource" ; $ string_to_sign = join ( "" , $ string_to_sign_builder ) ; $ signature = base64_encode ( hash_hmac ( "sha256" , utf8_encode ( $ string_to_sign ) , base64_decode ( $ api_key ) , true ) ) ; $ authorization = "TSA $customer_id:$signature" ; $ headers = [ "Authorization" => $ authorization , "Date" => $ date , "Content-Type" => $ content_type , "x-ts-auth-method" => $ auth_method , "x-ts-nonce" => $ nonce ] ; if ( $ user_agent ) { $ headers [ "User-Agent" ] = $ user_agent ; } return $ headers ; }
Generates the TeleSign REST API headers used to authenticate requests.

Creates the canonicalized string_to_sign and generates the HMAC signature. This is used to authenticate requests
against the TeleSign REST API.

See https://developer.telesign.com/docs/authentication-1 for detailed API documentation.

@param string $customer_id        Your account customer_id
@param string $api_key            Your account api_key
@param string $method_name        The HTTP method name of the request, should be one of 'POST', 'GET', 'PUT' or
'DELETE'
@param string $resource           The partial resource URI to perform the request against
@param string $url_encoded_fields HTTP body parameters to perform the HTTP request with, must be urlencoded
@param string $date               The date and time of the request
@param string $nonce              A unique cryptographic nonce for the request
@param string $user_agent         User Agent associated with the request

@return array The TeleSign authentication headers
Generates the TeleSign REST API headers used to authenticate requests .