1 | <?php |
||
36 | class Signer implements SignerInterface, LoggerAwareInterface |
||
37 | { |
||
38 | use LoggerAwareTrait; |
||
39 | |||
40 | |||
41 | /**************************************************************************/ |
||
42 | // PROPERTIES |
||
43 | |||
44 | /** @var string */ |
||
45 | private $self_key; |
||
46 | |||
47 | /** @var string */ |
||
48 | private $client_id; |
||
49 | |||
50 | /** @var string */ |
||
51 | private $client_secret; |
||
52 | |||
53 | /** @var string */ |
||
54 | private $hash_algo = ''; |
||
55 | |||
56 | |||
57 | /**************************************************************************/ |
||
58 | // PUBLIC METHODS |
||
59 | |||
60 | /** |
||
61 | * Constructs a new instance of this class. |
||
62 | * |
||
63 | * @param string $self_key A string which identifies the signing party and adds additional entropy. |
||
64 | * @param string $client_id A string which is the public portion of the keypair identifying the client party. |
||
65 | * The pairing of the public and private portions of the keypair should only be known |
||
66 | * to the client party and the signing party. |
||
67 | * @param string $client_secret A string which is the private portion of the keypair identifying the client party. |
||
68 | * The pairing of the public and private portions of the keypair should only be known |
||
69 | * to the client party and the signing party. |
||
70 | * @param string $hash_algo The hash algorithm to use for signing. Run `hash_algos()` to see what's supported. |
||
71 | * The default value is `sha512`. |
||
72 | * |
||
73 | * @see http://php.net/hash_algos |
||
74 | */ |
||
75 | public function __construct($self_key, $client_id, $client_secret, $hash_algo = 'sha512') |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function getSelfKey() |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getClientId() |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function getClientSecret() |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function sign(array $payload) |
||
125 | |||
126 | |||
127 | /**************************************************************************/ |
||
128 | // PRIVATE METHODS |
||
129 | |||
130 | /** |
||
131 | * Creates the string-to-sign based on a variety of factors. |
||
132 | * |
||
133 | * @param string $self_key A string which identifies the signing party and adds additional entropy. |
||
134 | * @param string $client_id A string which is the public portion of the keypair identifying the client party. |
||
135 | * @param string $scope The results of a call to the `createScope()` method. |
||
136 | * @param string $context The results of a call to the `createContext()` method. |
||
137 | * @return string The final string to be signed. |
||
138 | */ |
||
139 | private function createStringToSign($self_key, $client_id, $scope, $context) |
||
157 | |||
158 | /** |
||
159 | * An array of key-value pairs representing the data that you want to sign. |
||
160 | * All values must be `scalar`. |
||
161 | * |
||
162 | * @param array $payload The data that you want to sign. |
||
163 | * @return string A canonical string representation of the data to sign. |
||
164 | */ |
||
165 | private function createContext(array $payload) |
||
190 | |||
191 | /** |
||
192 | * Gets the salt value that should be used for signing. |
||
193 | * |
||
194 | * @param string $self_key A string which identifies the signing party and adds additional entropy. |
||
195 | * @param string $client_id A string which is the public portion of the keypair identifying the client party. |
||
196 | * @param string $client_secret A string which is the private portion of the keypair identifying the client party. |
||
197 | * @return string The signing salt. |
||
198 | */ |
||
199 | private function getSigningSalt($self_key, $client_id, $client_secret) |
||
221 | |||
222 | /** |
||
223 | * Creates the "scope" in which the signature is valid. |
||
224 | * |
||
225 | * @param string $self_key A string which identifies the signing party and adds additional entropy. |
||
226 | * @param string $client_id A string which is the public portion of the keypair identifying the client party. |
||
227 | * @return string The string which represents the scope in which the signature is valid. |
||
228 | */ |
||
229 | private function createScope($self_key, $client_id) |
||
244 | } |
||
245 |