Skip to content

Commit 930ebe2

Browse files
committed
Implemented authenticated calls
1 parent 05fbc4a commit 930ebe2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Api.php

+21
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public function doCall(
8383
$parameters['method'] = (string) $method;
8484
$parameters['format'] = 'json';
8585

86+
// when we need authentication we need to add some extra parameters
87+
if ($authenticate) {
88+
$parameters['email'] = $this->getEmail();
89+
$parameters['nonce'] = md5(microtime(true) + rand(0, time()));
90+
$parameters['secret'] = $this->getSecret($parameters['nonce']);
91+
}
92+
8693
// HTTP method
8794
if ($httpMethod == 'POST') {
8895
$options[CURLOPT_POST] = true;
@@ -172,6 +179,20 @@ public function getTimeOut()
172179
return $this->timeOut;
173180
}
174181

182+
/**
183+
* Calculate the secret
184+
*
185+
* @param string $nonce
186+
* @return string
187+
*/
188+
private function getSecret($nonce)
189+
{
190+
$base = $this->getEmail();
191+
$base .= $this->getApiKey();
192+
193+
return sha1(md5($nonce) . md5($base));
194+
}
195+
175196
/**
176197
* Get the useragent that will be used. Our version will be prepended to
177198
* yours.

0 commit comments

Comments
 (0)