|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Canis.io |
|
4
|
|
|
* @license MIT |
|
5
|
|
|
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace Canis\Lumen\Jwt\Adapters\Lcobucci; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class that wraps validation values |
|
11
|
|
|
* Jacob added the ability to override just the expiration validator |
|
12
|
|
|
* |
|
13
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
|
14
|
|
|
* @author Jacob Morrison <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class ValidationData |
|
17
|
|
|
extends \Lcobucci\JWT\ValidationData |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The list of things to be validated |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
private $items; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initializes the object |
|
28
|
|
|
* |
|
29
|
|
|
* @param int $currentTime |
|
30
|
|
|
*/ |
|
31
|
25 |
|
public function __construct($currentTime = null) |
|
32
|
|
|
{ |
|
33
|
25 |
|
$currentTime = $currentTime ?: time(); |
|
34
|
|
|
|
|
35
|
25 |
|
$this->items = [ |
|
36
|
25 |
|
'jti' => null, |
|
37
|
25 |
|
'iss' => null, |
|
38
|
25 |
|
'aud' => null, |
|
39
|
25 |
|
'sub' => null, |
|
40
|
25 |
|
'iat' => $currentTime, |
|
41
|
25 |
|
'nbf' => $currentTime, |
|
42
|
|
|
'exp' => $currentTime |
|
43
|
25 |
|
]; |
|
44
|
25 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Configures the id |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $id |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function setId($id) |
|
52
|
|
|
{ |
|
53
|
1 |
|
$this->items['jti'] = (string) $id; |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Configures the issuer |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $issuer |
|
60
|
|
|
*/ |
|
61
|
18 |
|
public function setIssuer($issuer) |
|
62
|
|
|
{ |
|
63
|
18 |
|
$this->items['iss'] = (string) $issuer; |
|
64
|
18 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Configures the audience |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $audience |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function setAudience($audience) |
|
72
|
|
|
{ |
|
73
|
2 |
|
$this->items['aud'] = (string) $audience; |
|
74
|
2 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Configures the subject |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $subject |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function setSubject($subject) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$this->items['sub'] = (string) $subject; |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Configures the time that "iat", "nbf" and "exp" should be based on |
|
88
|
|
|
* |
|
89
|
|
|
* @param int $currentTime |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function setCurrentTime($currentTime) |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->items['iat'] = (int) $currentTime; |
|
94
|
1 |
|
$this->items['nbf'] = (int) $currentTime; |
|
95
|
1 |
|
$this->items['exp'] = (int) $currentTime; |
|
96
|
1 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Configures the time that "exp" should be based on |
|
100
|
|
|
* |
|
101
|
|
|
* @param int $currentTime |
|
102
|
|
|
*/ |
|
103
|
8 |
|
public function setExpiration($currentTime) |
|
104
|
|
|
{ |
|
105
|
8 |
|
$this->items['exp'] = (int) $currentTime; |
|
106
|
8 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Returns the requested item |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $name |
|
112
|
|
|
* |
|
113
|
|
|
* @return mixed |
|
114
|
|
|
*/ |
|
115
|
24 |
|
public function get($name) |
|
116
|
|
|
{ |
|
117
|
24 |
|
return isset($this->items[$name]) ? $this->items[$name] : null; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Returns if the item is present |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $name |
|
124
|
|
|
* |
|
125
|
|
|
* @return boolean |
|
126
|
|
|
*/ |
|
127
|
18 |
|
public function has($name) |
|
128
|
|
|
{ |
|
129
|
18 |
|
return !empty($this->items[$name]); |
|
130
|
|
|
} |
|
131
|
|
|
} |