1 | <?php |
||
5 | class Token |
||
6 | { |
||
7 | /** |
||
8 | * The Client instance. |
||
9 | * |
||
10 | * @var \ElfSundae\Laravel\Api\Client |
||
11 | */ |
||
12 | protected $client; |
||
13 | |||
14 | /** |
||
15 | * Constructor. |
||
16 | * |
||
17 | * @param \ElfSundae\Laravel\Api\Client $client |
||
18 | */ |
||
19 | public function __construct(Client $client) |
||
23 | |||
24 | /** |
||
25 | * Get the Client instance. |
||
26 | * |
||
27 | * @return \ElfSundae\Laravel\Api\Client |
||
28 | */ |
||
29 | public function getClient() |
||
33 | |||
34 | /** |
||
35 | * Set the Client instance. |
||
36 | * |
||
37 | * @param \ElfSundae\Laravel\Api\Client $client |
||
38 | */ |
||
39 | public function setClient(Client $client) |
||
43 | |||
44 | /** |
||
45 | * Generate an api token. |
||
46 | * |
||
47 | * @param string $key |
||
48 | * @param string $secret |
||
49 | * @param string|int $time |
||
50 | * @return string|null |
||
51 | */ |
||
52 | public function generate($key, $secret, $time) |
||
53 | { |
||
54 | if ($key && $secret && $time) { |
||
55 | return substr(md5($key.$secret.$time), 10, 20); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Generate an api token for the given app key. |
||
61 | * |
||
62 | * @param string $key |
||
63 | * @param string|int $time |
||
64 | * @return string|null |
||
65 | */ |
||
66 | public function generateForKey($key, $time) |
||
67 | { |
||
68 | return $this->generate($key, $this->client->getAppSecretForKey($key), $time); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Verify an api token. |
||
73 | * |
||
74 | * @param string $token |
||
75 | * @param string $key |
||
76 | * @param string|int $time |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function verify($token, $key, $time) |
||
83 | |||
84 | /** |
||
85 | * Generate a token data array. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * @param string $secret |
||
89 | * @param string|int|null $time |
||
90 | * @return array |
||
91 | */ |
||
92 | public function generateData($key, $secret, $time = null) |
||
99 | |||
100 | /** |
||
101 | * Generate a token data array. |
||
102 | * |
||
103 | * @param string $key |
||
104 | * @param string|int|null $time |
||
105 | * @return array |
||
106 | */ |
||
107 | public function generateDataForKey($key, $time = null) |
||
115 | |||
116 | /** |
||
117 | * Generate HTTP headers with a new token. |
||
118 | * |
||
119 | * @param string $appKey |
||
120 | * @param string|int|null $time |
||
121 | * @return array |
||
122 | */ |
||
123 | public function generateHttpHeaders($appKey, $time = null) |
||
133 | |||
134 | /** |
||
135 | * Generate query data with a new token. |
||
136 | * |
||
137 | * @param string $appKey |
||
138 | * @param string|int|null $time |
||
139 | * @return array |
||
140 | */ |
||
141 | public function generateQueryData($appKey, $time = null) |
||
151 | |||
152 | /** |
||
153 | * Generate query string with a new token. |
||
154 | * |
||
155 | * @param string $appKey |
||
156 | * @param string|int|null $time |
||
157 | * @return string |
||
158 | */ |
||
159 | public function generateQueryString($appKey, $time = null) |
||
163 | } |
||
164 |