1 | <?php |
||
21 | class Ticket { |
||
22 | |||
23 | /** |
||
24 | * Service Ticket |
||
25 | */ |
||
26 | const TYPE_ST = 'ST'; |
||
27 | |||
28 | /** |
||
29 | * Proxy Ticket |
||
30 | */ |
||
31 | const TYPE_PT = 'PT'; |
||
32 | |||
33 | /** |
||
34 | * Proxy-Granting Ticket |
||
35 | */ |
||
36 | const TYPE_PGT = 'PGT'; |
||
37 | |||
38 | /** |
||
39 | * Proxy-Granting Ticket IOU |
||
40 | */ |
||
41 | const TYPE_PGTIOU = 'PGTIOU'; |
||
42 | |||
43 | /** |
||
44 | * Ticket-Granting Cookie |
||
45 | */ |
||
46 | const TYPE_TGC = 'TGC'; |
||
47 | |||
48 | /** |
||
49 | * Login Ticket |
||
50 | */ |
||
51 | const TYPE_LT = 'LT'; |
||
52 | |||
53 | /** |
||
54 | * Ticket type. |
||
55 | * @var string |
||
56 | */ |
||
57 | public $type; |
||
58 | |||
59 | /** |
||
60 | * Authenticated WordPress user who owns the ticket. |
||
61 | * @var WP_User |
||
62 | */ |
||
63 | public $user; |
||
64 | |||
65 | /** |
||
66 | * URL for the service that requested authentication. |
||
67 | * @var string |
||
68 | */ |
||
69 | public $service; |
||
70 | |||
71 | /** |
||
72 | * Expiration timestamp, in seconds. |
||
73 | * @var float |
||
74 | */ |
||
75 | public $expires; |
||
76 | |||
77 | /** |
||
78 | * CAS ticket constructor. |
||
79 | * |
||
80 | * @param string $type Ticket type. |
||
81 | * @param WP_User $user Authenticated WordPress user who owns the ticket. |
||
82 | * @param string $service URL for the service that requested authentication. |
||
83 | * @param double $expires Expiration timestamp, in seconds. |
||
84 | * Freshly generated tickets should not provide this value. |
||
85 | * |
||
86 | * @todo "Remember-Me" tickets should have an expiration date of up to 3 months. |
||
87 | */ |
||
88 | public function __construct( $type, $user, $service, $expires = 0.0 ) { |
||
114 | |||
115 | /** |
||
116 | * Magic method that returns the ticket as a string. |
||
117 | * |
||
118 | * @return string Ticket as string. |
||
119 | */ |
||
120 | public function __toString() { |
||
123 | |||
124 | /** |
||
125 | * Create a new ticket instance from a ticket string. |
||
126 | * |
||
127 | * @param string $string Ticket string. |
||
128 | * @return Ticket Ticket object. |
||
129 | * |
||
130 | * @throws \Cassava\Exception\TicketException |
||
131 | * |
||
132 | * @uses \__() |
||
133 | * @uses \get_user_by() |
||
134 | * @uses \is_wp_error() |
||
135 | */ |
||
136 | public static function fromString( $string ) { |
||
162 | |||
163 | /** |
||
164 | * Serialize ticket components into a string. |
||
165 | * |
||
166 | * @return string Ticket string. |
||
167 | */ |
||
168 | protected function encodeTicket() { |
||
178 | |||
179 | /** |
||
180 | * Extracts components from a base64 encoded ticket string. |
||
181 | * |
||
182 | * @param string $ticket Ticket string (minus the prefix). |
||
183 | * @return array Ticket components. |
||
184 | * |
||
185 | * @throws \Cassava\Exception\TicketException |
||
186 | * |
||
187 | * @uses \__() |
||
188 | */ |
||
189 | protected static function decodeTicket( $ticket ) { |
||
211 | |||
212 | /** |
||
213 | * Generate security key for a ticket. |
||
214 | * |
||
215 | * @return string Generated security key. |
||
216 | * |
||
217 | * @uses \wp_hash() |
||
218 | */ |
||
219 | protected function generateKey() { |
||
227 | |||
228 | /** |
||
229 | * Create a ticket signature by concatenating components and signing them with a key. |
||
230 | * |
||
231 | * @return string Generated signature hash. |
||
232 | */ |
||
233 | public function generateSignature() { |
||
241 | |||
242 | /** |
||
243 | * Validates a ticket string against a list of expected types. |
||
244 | * |
||
245 | * @param string $ticket Ticket string to validate. |
||
246 | * @param array $types List of allowed type prefixes. |
||
247 | * |
||
248 | * @throws \Cassava\Exception\TicketException |
||
249 | */ |
||
250 | public static function validateAllowedTypes( $ticket, $types = array() ) { |
||
257 | |||
258 | /** |
||
259 | * Remember a fresh ticket using WordPress's Transients API. |
||
260 | * |
||
261 | * @uses \set_transient() |
||
262 | */ |
||
263 | protected function markUnused() { |
||
267 | |||
268 | /** |
||
269 | * Remember a ticket as having been used using WordPress's Transients API. |
||
270 | * |
||
271 | * @uses \delete_transient() |
||
272 | * |
||
273 | * @todo "Remember-Me" tickets should not be invalidated. |
||
274 | */ |
||
275 | public function markUsed() { |
||
279 | |||
280 | /** |
||
281 | * Checks whether a ticket has been used using WordPress's Transients API. |
||
282 | * |
||
283 | * @return boolean Whether the ticket has been used. |
||
284 | * |
||
285 | * @uses \get_transient() |
||
286 | */ |
||
287 | public function isUsed() { |
||
297 | |||
298 | } |
||
299 |