1 | <?php |
||
14 | class ValidationContext |
||
15 | { |
||
16 | /** |
||
17 | * Reference time. |
||
18 | * |
||
19 | * @var int $_refTime |
||
20 | */ |
||
21 | protected $_refTime; |
||
22 | |||
23 | /** |
||
24 | * Leeway in seconds for the reference time constraints. |
||
25 | * |
||
26 | * @var int $_leeway |
||
27 | */ |
||
28 | protected $_leeway; |
||
29 | |||
30 | /** |
||
31 | * Validation constraints. |
||
32 | * |
||
33 | * @var array $_constraints |
||
34 | */ |
||
35 | protected $_constraints; |
||
36 | |||
37 | /** |
||
38 | * Set of JSON Web Keys usable for the validation. |
||
39 | * |
||
40 | * @var JWKSet $_keys |
||
41 | */ |
||
42 | protected $_keys; |
||
43 | |||
44 | /** |
||
45 | * Whether to allow unsecured JWT's, that is, claims without integrity |
||
46 | * protection nor encryption. |
||
47 | * |
||
48 | * @var bool $_allowUnsecured |
||
49 | */ |
||
50 | protected $_allowUnsecured; |
||
51 | |||
52 | /** |
||
53 | * Constructor |
||
54 | * |
||
55 | * @param array $constraints Optional array of constraints keyed by claim |
||
56 | * names |
||
57 | * @param JWKSet $keys Optional set of JSON Web Keys used for signature |
||
58 | * validation and/or decryption. |
||
59 | */ |
||
60 | 39 | public function __construct(array $constraints = null, JWKSet $keys = null) { |
|
67 | |||
68 | /** |
||
69 | * Initialize with a single JSON Web Key. |
||
70 | * |
||
71 | * @param JWK $key JSON Web Key |
||
72 | * @param array $constraints Optional constraints |
||
73 | * @return self |
||
74 | */ |
||
75 | 3 | public static function fromKey(JWK $key, array $constraints = []) { |
|
78 | |||
79 | /** |
||
80 | * Get self with reference time. |
||
81 | * |
||
82 | * @param int|null $ts Unix timestamp |
||
83 | * @return self |
||
84 | */ |
||
85 | 23 | public function withReferenceTime($ts) { |
|
90 | |||
91 | /** |
||
92 | * Check whether reference time is set. |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 20 | public function hasReferenceTime() { |
|
99 | |||
100 | /** |
||
101 | * Get reference time. |
||
102 | * |
||
103 | * @throws \LogicException |
||
104 | * @return int |
||
105 | */ |
||
106 | 13 | public function referenceTime() { |
|
112 | |||
113 | /** |
||
114 | * Get self with reference time leeway. |
||
115 | * |
||
116 | * @param int $seconds |
||
117 | * @return self |
||
118 | */ |
||
119 | 11 | public function withLeeway($seconds) { |
|
124 | |||
125 | /** |
||
126 | * Get reference time leeway. |
||
127 | * |
||
128 | * @return int |
||
129 | */ |
||
130 | 12 | public function leeway() { |
|
133 | |||
134 | /** |
||
135 | * Get self with validation constraint. |
||
136 | * |
||
137 | * @param string $name Claim name |
||
138 | * @param mixed $constraint Value to check claim against |
||
139 | * @return self |
||
140 | */ |
||
141 | 14 | public function withConstraint($name, $constraint) { |
|
146 | |||
147 | /** |
||
148 | * Get self with issuer constraint. |
||
149 | * |
||
150 | * @param string $issuer |
||
151 | * @return self |
||
152 | */ |
||
153 | 4 | public function withIssuer($issuer) { |
|
156 | |||
157 | /** |
||
158 | * Get self with subject constraint. |
||
159 | * |
||
160 | * @param string $subject |
||
161 | * @return self |
||
162 | */ |
||
163 | 3 | public function withSubject($subject) { |
|
166 | |||
167 | /** |
||
168 | * Get self with audience constraint. |
||
169 | * |
||
170 | * @param string $audience |
||
171 | * @return self |
||
172 | */ |
||
173 | 3 | public function withAudience($audience) { |
|
176 | |||
177 | /** |
||
178 | * Get self with JWT ID constraint. |
||
179 | * |
||
180 | * @param string $id |
||
181 | * @return self |
||
182 | */ |
||
183 | 3 | public function withID($id) { |
|
186 | |||
187 | /** |
||
188 | * Check whether constraint is present. |
||
189 | * |
||
190 | * @param string $name Claim name |
||
191 | * @return bool |
||
192 | */ |
||
193 | 33 | public function hasConstraint($name) { |
|
196 | |||
197 | /** |
||
198 | * Get constraint by claim name. |
||
199 | * |
||
200 | * @param string $name |
||
201 | * @throws \LogicException |
||
202 | * @return mixed Constraint value |
||
203 | */ |
||
204 | 20 | public function constraint($name) { |
|
210 | |||
211 | /** |
||
212 | * Get the set of JSON Web Keys defined in this context. |
||
213 | * |
||
214 | * @return JWKSet |
||
215 | */ |
||
216 | 8 | public function keys() { |
|
219 | |||
220 | /** |
||
221 | * Get self with 'allow unsecured' flag set. |
||
222 | * |
||
223 | * @param bool $allow Whether to allow unsecured JWT's |
||
224 | * @return self |
||
225 | */ |
||
226 | 3 | public function withUnsecuredAllowed($allow) { |
|
231 | |||
232 | /** |
||
233 | * Check whether unsecured JWT's are allowed. |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | 3 | public function isUnsecuredAllowed() { |
|
240 | |||
241 | /** |
||
242 | * Validate claims. |
||
243 | * |
||
244 | * @param Claims $claims |
||
245 | * @throws \RuntimeException If any of the claims is not valid |
||
246 | * @return self |
||
247 | */ |
||
248 | 25 | public function validate(Claims $claims) { |
|
257 | } |
||
258 |