1 | <?php |
||
20 | class JWT |
||
21 | { |
||
22 | use CustomClaims; |
||
23 | |||
24 | /** |
||
25 | * @var \Tymon\JWTAuth\Manager |
||
26 | */ |
||
27 | protected $manager; |
||
28 | |||
29 | /** |
||
30 | * @var \Tymon\JWTAuth\Http\Parser |
||
31 | */ |
||
32 | protected $parser; |
||
33 | |||
34 | /** |
||
35 | * @var \Tymon\JWTAuth\Token |
||
36 | */ |
||
37 | protected $token; |
||
38 | |||
39 | /** |
||
40 | * @param \Tymon\JWTAuth\Manager $manager |
||
41 | * @param \Tymon\JWTAuth\Http\Parser $parser |
||
42 | */ |
||
43 | 38 | public function __construct(Manager $manager, Parser $parser) |
|
48 | |||
49 | /** |
||
50 | * Generate a token using the user identifier as the subject claim. |
||
51 | * |
||
52 | * @param \Tymon\JWTAuth\Contracts\JWTSubject $user |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | 4 | public function fromUser(JWTSubject $user) |
|
62 | |||
63 | /** |
||
64 | * Refresh an expired token. |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 2 | public function refresh() |
|
74 | |||
75 | /** |
||
76 | * Invalidate a token (add it to the blacklist). |
||
77 | * |
||
78 | * @param boolean $forceForever |
||
79 | * |
||
80 | * @return boolean |
||
81 | */ |
||
82 | 4 | public function invalidate($forceForever = false) |
|
88 | |||
89 | /** |
||
90 | * Alias to get the payload, and as a result checks that |
||
91 | * the token is valid i.e. not expired or blacklisted |
||
92 | * |
||
93 | * @throws JWTException |
||
94 | * |
||
95 | * @return \Tymon\JWTAuth\Payload |
||
96 | */ |
||
97 | 4 | public function checkOrFail() |
|
101 | |||
102 | /** |
||
103 | * Check that the token is valid |
||
104 | * |
||
105 | * @return boolean |
||
106 | */ |
||
107 | 4 | public function check() |
|
117 | |||
118 | /** |
||
119 | * Get the token. |
||
120 | * |
||
121 | * @return false|Token |
||
122 | */ |
||
123 | 6 | public function getToken() |
|
135 | |||
136 | /** |
||
137 | * Parse the token from the request. |
||
138 | * |
||
139 | * @throws \Tymon\JWTAuth\Exceptions\JWTException |
||
140 | * |
||
141 | * @return JWTAuth |
||
142 | */ |
||
143 | 12 | public function parseToken() |
|
151 | |||
152 | /** |
||
153 | * Get the raw Payload instance. |
||
154 | * |
||
155 | * @return \Tymon\JWTAuth\Payload |
||
156 | */ |
||
157 | 10 | public function getPayload() |
|
163 | |||
164 | /** |
||
165 | * Create a Payload instance. |
||
166 | * |
||
167 | * @param \Tymon\JWTAuth\Contracts\JWTSubject $user |
||
168 | * |
||
169 | * @return \Tymon\JWTAuth\Payload |
||
170 | */ |
||
171 | 4 | public function makePayload(JWTSubject $user) |
|
175 | |||
176 | /** |
||
177 | * Build the claims array and return it |
||
178 | * |
||
179 | * @param \Tymon\JWTAuth\Contracts\JWTSubject $user |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | 4 | protected function getClaimsArray(JWTSubject $user) |
|
191 | |||
192 | /** |
||
193 | * Get the authenticated user |
||
194 | * |
||
195 | * @return \Tymon\JWTAuth\Contracts\JWTSubject |
||
196 | */ |
||
197 | 4 | public function user() |
|
201 | |||
202 | /** |
||
203 | * Set the token. |
||
204 | * |
||
205 | * @param Token|string $token |
||
206 | * |
||
207 | * @return JWTAuth |
||
208 | */ |
||
209 | 18 | public function setToken($token) |
|
215 | |||
216 | /** |
||
217 | * Unset the current token. |
||
218 | * |
||
219 | * @return JWTAuth |
||
220 | */ |
||
221 | public function unsetToken() |
||
227 | |||
228 | /** |
||
229 | * Ensure that a token is available. |
||
230 | * |
||
231 | * @throws \Tymon\JWTAuth\Exceptions\JWTException |
||
232 | */ |
||
233 | 16 | protected function requireToken() |
|
239 | |||
240 | /** |
||
241 | * Set the request instance. |
||
242 | * |
||
243 | * @param \Illuminate\Http\Request $request |
||
244 | * |
||
245 | * @return JWTAuth |
||
246 | */ |
||
247 | 2 | public function setRequest(Request $request) |
|
253 | |||
254 | /** |
||
255 | * Get the Manager instance. |
||
256 | * |
||
257 | * @return \Tymon\JWTAuth\Manager |
||
258 | */ |
||
259 | 4 | public function manager() |
|
263 | |||
264 | /** |
||
265 | * Get the Parser instance |
||
266 | * |
||
267 | * @return \Tymon\JWTAuth\Http\Parser |
||
268 | */ |
||
269 | 2 | public function parser() |
|
273 | |||
274 | /** |
||
275 | * Get the Payload Factory |
||
276 | * |
||
277 | * @return \Tymon\JWTAuth\Factory |
||
278 | */ |
||
279 | 4 | public function factory() |
|
283 | |||
284 | /** |
||
285 | * Get the Blacklist |
||
286 | * |
||
287 | * @return \Tymon\JWTAuth\Blacklist |
||
288 | */ |
||
289 | public function blacklist() |
||
293 | |||
294 | /** |
||
295 | * Magically call the JWT Manager. |
||
296 | * |
||
297 | * @param string $method |
||
298 | * @param array $parameters |
||
299 | * |
||
300 | * @return mixed |
||
301 | * |
||
302 | * @throws \BadMethodCallException |
||
303 | */ |
||
304 | 2 | public function __call($method, $parameters) |
|
312 | } |
||
313 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: