|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the tiqr project. |
|
4
|
|
|
* |
|
5
|
|
|
* The tiqr project aims to provide an open implementation for |
|
6
|
|
|
* authentication using mobile devices. It was initiated by |
|
7
|
|
|
* SURFnet and developed by Egeniq. |
|
8
|
|
|
* |
|
9
|
|
|
* More information: http://www.tiqr.org |
|
10
|
|
|
* |
|
11
|
|
|
* @author Ivo Jansch <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @package tiqr |
|
14
|
|
|
* |
|
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright (C) 2010-2011 SURFnet BV |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A DeviceStorage implementation that uses a tokenexhange server to swap |
|
23
|
|
|
* notificationTokens for deviceTokens. |
|
24
|
|
|
* |
|
25
|
|
|
* The following options can be passed when creating a tokenexchange instance |
|
26
|
|
|
* (which should be done through the Tiqr_DeviceStorage factory): |
|
27
|
|
|
* - 'appid' the app identifier of the client app used to exchange tokens, |
|
28
|
|
|
* must match the appid used in the mobile client apps. |
|
29
|
|
|
* - 'url' the url of the tokenexchange service |
|
30
|
|
|
* |
|
31
|
|
|
* @author ivo |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
class Tiqr_DeviceStorage_TokenExchange extends Tiqr_DeviceStorage_Abstract |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @see Tiqr_DeviceStorage_Abstract::getDeviceToken() |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getDeviceToken(string $notificationToken) |
|
40
|
|
|
{ |
|
41
|
|
|
$url = $this->_options["url"]."?appId=".$this->_options["appid"]; |
|
42
|
|
|
|
|
43
|
|
|
$url.= "¬ificationToken=".$notificationToken; |
|
44
|
|
|
|
|
45
|
|
|
$ch = curl_init(); |
|
46
|
|
|
|
|
47
|
|
|
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); |
|
48
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
|
49
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
50
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
51
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
|
52
|
|
|
|
|
53
|
|
|
$output = curl_exec($ch); |
|
54
|
|
|
curl_close($ch); |
|
55
|
|
|
|
|
56
|
|
|
if (stripos($output, "not found")!==false) { |
|
|
|
|
|
|
57
|
|
|
$this->logger->error('Token Exchange failed and responded with: not found', ['full output' => $output]); |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (stripos($output, "error")!==false) { |
|
62
|
|
|
$this->logger->error('Token Exchange failed and responded with: error', ['full output' => $output]); |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
$this->logger->notice(sprintf('Token exchange returned output: %s', $output)); |
|
|
|
|
|
|
66
|
|
|
return trim($output); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|