Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 
<?php

namespace Apptus\ESales\Connector;

/**
 * A class that should be used for creating personal customer keys when using eSales Web-API.
 */
class CustomerKeyAuthentication
{
    private $customerKey;
    private $token;

    /**
     * Creates a new instance that contains a personal customer key and a token, that can be used for
     * cross-device client-side notifications in eSales Web API. This object should be created
     * when the user has successfully logged in, and the respective values should be set in cookies.
     * See {@see getCustomerKey()} and {@see getToken()}.
     * @param $privateKey string A private key that is unique for this site. This key is provided by Apptus.
     * @param $user string The user name, or other user-unique value, of the customer that logged in.
     * @throws \InvalidArgumentException If privateKey or user is null or empty.
     */
    public function __construct($privateKey, $user)
    {
        $this->customerKey = hash('sha256', $user);
        $messageAuthentication = new MessageAuthentication($privateKey);
        $this->token = $messageAuthentication->sign($this->customerKey);
    }

    /**
     * @return string A hash based on a user specific value, such as user name.
     * This value should be stored in a cookie named "apptus.customerKey".
     */
    public function getCustomerKey()
    {
        return $this->customerKey;
    }

    /**
     * @return string The signature of this customerKey.
     * This value should be stored in a cookie named "apptus.token".
     */
    public function getToken()
    {
        return $this->token;
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen