6 public function authenticate(Config $config)
8 if ($config->access === false) {
9 throw new \Exception('Authentication not setup');
11 if ($config->access === true) {
12 //Access without restrictions allowed
16 if (!isset($_GET['atoken'])) {
17 throw new \Exception('Parameter missing: atoken');
19 if (!isset($_GET['asignature'])) {
20 throw new \Exception('Parameter missing: asignature');
22 if (!isset($_GET['atimestamp'])) {
23 throw new \Exception('Parameter missing: atimestamp');
26 $token = $_GET['atoken'];
27 if (!array_key_exists($token, $config->access)) {
28 throw new \Exception('Unknown atoken');
31 $timestamp = (int) $_GET['atimestamp'];
32 if ($timestamp + $config->timestampLifetime < time()) {
33 throw new \Exception('atimestamp too old');
36 $signature = $_GET['asignature'];
39 unset($params['asignature']);
40 $sigdata = $this->getSignatureData($params);
42 $verifiedSignature = hash_hmac('sha1', $sigdata, $config->access[$token]);
43 if ($signature !== $verifiedSignature) {
44 throw new \Exception('Invalid signature');
49 protected function getSignatureData($params)
53 foreach ($params as $key => $value) {
54 $encparams[] = $key . '=' . rawurlencode($value);
56 return implode('&', $encparams);