def generate_telesign_headers(customer_id,
                                  api_key,
                                  method_name,
                                  resource,
                                  url_encoded_fields,
                                  date_rfc2616=None,
                                  nonce=None,
                                  user_agent=None,
                                  content_type=None):
        """
        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 for detailed API documentation.

        :param customer_id: Your account customer_id.
        :param api_key: Your account api_key.
        :param method_name: The HTTP method name of the request as a upper case string, should be one of 'POST', 'GET',
            'PUT' or 'DELETE'.
        :param resource: The partial resource URI to perform the request against, as a string.
        :param url_encoded_fields: HTTP body parameters to perform the HTTP request with, must be a urlencoded string.
        :param date_rfc2616: The date and time of the request formatted in rfc 2616, as a string.
        :param nonce: A unique cryptographic nonce for the request, as a string.
        :param user_agent: (optional) User Agent associated with the request, as a string.
        :param content_type: (optional) ContentType of the request, as a string.
        :return: The TeleSign authentication headers.
        """
        if date_rfc2616 is None:
            date_rfc2616 = formatdate(usegmt=True)

        if nonce is None:
            nonce = str(uuid.uuid4())
        
        if not content_type:
            content_type = "application/x-www-form-urlencoded" if method_name in ("POST", "PUT") else ""

        auth_method = "HMAC-SHA256"

        string_to_sign_builder = ["{method}".format(method=method_name)]

        string_to_sign_builder.append("\n{content_type}".format(content_type=content_type))

        string_to_sign_builder.append("\n{date}".format(date=date_rfc2616))

        string_to_sign_builder.append("\nx-ts-auth-method:{auth_method}".format(auth_method=auth_method))

        string_to_sign_builder.append("\nx-ts-nonce:{nonce}".format(nonce=nonce))

        if content_type and url_encoded_fields:
            string_to_sign_builder.append("\n{fields}".format(fields=url_encoded_fields))

        string_to_sign_builder.append("\n{resource}".format(resource=resource))

        string_to_sign = "".join(string_to_sign_builder)

        signer = hmac.new(b64decode(api_key), string_to_sign.encode("utf-8"), sha256)
        signature = b64encode(signer.digest()).decode("utf-8")

        authorization = "TSA {customer_id}:{signature}".format(
            customer_id=customer_id,
            signature=signature)

        headers = {
            "Authorization": authorization,
            "Date": date_rfc2616,
            "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 for detailed API documentation.

        :param customer_id: Your account customer_id.
        :param api_key: Your account api_key.
        :param method_name: The HTTP method name of the request as a upper case string, should be one of 'POST', 'GET',
            'PUT' or 'DELETE'.
        :param resource: The partial resource URI to perform the request against, as a string.
        :param url_encoded_fields: HTTP body parameters to perform the HTTP request with, must be a urlencoded string.
        :param date_rfc2616: The date and time of the request formatted in rfc 2616, as a string.
        :param nonce: A unique cryptographic nonce for the request, as a string.
        :param user_agent: (optional) User Agent associated with the request, as a string.
        :param content_type: (optional) ContentType of the request, as a string.
        :return: The TeleSign authentication headers.