1 | <?php |
||
10 | class TokenGenerator |
||
11 | { |
||
12 | protected $sign; |
||
13 | protected $ttl; |
||
14 | protected $base64url; |
||
15 | |||
16 | /** |
||
17 | * Create a new TokenGenerator. |
||
18 | * |
||
19 | * `$ttl` is used for calculating the expiration time of the tokens, its default value (1440sec === 24min) |
||
20 | * correspond to the default `session.gc_maxlifetime`. |
||
21 | * |
||
22 | * @see http://php.net/manual/en/session.configuration.php Documentation of `session.gc-maxlifetime` |
||
23 | * |
||
24 | * @param callable $sign Callable used for generating the token signatures |
||
25 | * @param int $ttl Default Time to Live in seconds |
||
26 | */ |
||
27 | public function __construct(callable $sign, $ttl = 1440) |
||
41 | |||
42 | /** |
||
43 | * Generate the payload of a CSRF token. |
||
44 | * |
||
45 | * @param string $nonce Value used to associate a client session |
||
46 | * @param int $iat The time that the token was issued, defaults to `time()` |
||
47 | * @param int $exp The expiration time |
||
48 | * |
||
49 | * @return \stdClass |
||
50 | */ |
||
51 | protected function generatePayload($nonce, $iat, $exp) |
||
61 | |||
62 | /** |
||
63 | * Generate a CSRF token. |
||
64 | * |
||
65 | * @param string $nonce Value used to associate a client session |
||
66 | * @param int $iat The time that the token was issued, defaults to `time()` |
||
67 | * @param int $exp The expiration time, defaults to `$iat + $this->ttl` |
||
68 | * |
||
69 | * @return string |
||
70 | * |
||
71 | * @throws \InvalidArgumentException For invalid $iat, $exp and $nonce arguments |
||
72 | */ |
||
73 | public function __invoke($nonce, $iat = null, $exp = null) |
||
105 | } |
||
106 |