1 | <?php |
||
12 | class JWTAuth |
||
13 | { |
||
14 | /** |
||
15 | * @var \Tymon\JWTAuth\JWTManager |
||
16 | */ |
||
17 | protected $manager; |
||
18 | |||
19 | /** |
||
20 | * @var \Tymon\JWTAuth\Providers\User\UserInterface |
||
21 | */ |
||
22 | protected $user; |
||
23 | |||
24 | /** |
||
25 | * @var \Tymon\JWTAuth\Providers\Auth\AuthInterface |
||
26 | */ |
||
27 | protected $auth; |
||
28 | |||
29 | /** |
||
30 | * @var \Illuminate\Http\Request |
||
31 | */ |
||
32 | protected $request; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $identifier = 'id'; |
||
38 | |||
39 | /** |
||
40 | * @var \Tymon\JWTAuth\Token |
||
41 | */ |
||
42 | protected $token; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @var \Illuminate\Contracts\Auth\Authenticatable |
||
47 | */ |
||
48 | protected $userModel = null; |
||
49 | |||
50 | /** |
||
51 | * @param \Tymon\JWTAuth\JWTManager $manager |
||
52 | * @param \Tymon\JWTAuth\Providers\User\UserInterface $user |
||
53 | * @param \Tymon\JWTAuth\Providers\Auth\AuthInterface $auth |
||
54 | * @param \Illuminate\Http\Request $request |
||
55 | */ |
||
56 | 54 | public function __construct(JWTManager $manager, UserInterface $user, AuthInterface $auth, Request $request) |
|
63 | |||
64 | /** |
||
65 | * @return \Illuminate\Contracts\Auth\Authenticatable |
||
66 | */ |
||
67 | 3 | public function getUserModel() |
|
71 | |||
72 | /** |
||
73 | * @param \Illuminate\Contracts\Auth\Authenticatable $userModel |
||
74 | */ |
||
75 | public function setUserModel(Authenticatable $userModel) |
||
79 | |||
80 | |||
81 | |||
82 | /** |
||
83 | * Find a user using the user identifier in the subject claim. |
||
84 | * |
||
85 | * @param bool|string $token |
||
86 | * |
||
87 | * @return mixed |
||
88 | */ |
||
89 | 9 | public function toUser($token = false) |
|
103 | |||
104 | /** |
||
105 | * Generate a token using the user identifier as the subject claim. |
||
106 | * |
||
107 | * @param mixed $user |
||
108 | * @param array $customClaims |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 6 | public function fromUser($user, array $customClaims = []) |
|
118 | |||
119 | /** |
||
120 | * Attempt to authenticate the user and return the token. |
||
121 | * |
||
122 | * @param array $credentials |
||
123 | * @param array $customClaims |
||
124 | * |
||
125 | * @return false|string |
||
126 | * @throws JWTException |
||
127 | */ |
||
128 | 6 | public function attempt(array $credentials = [], array $customClaims = []) |
|
136 | |||
137 | /** |
||
138 | * Authenticate a user via a token. |
||
139 | * |
||
140 | * @param mixed $token |
||
141 | * @param Array $custom custom claims that must be equals (all custom fields indicated must be equals in token, this doesn't entail that the token must have only these claims) |
||
142 | * @return mixed |
||
143 | */ |
||
144 | 6 | public function authenticate($token = false, $custom = []) |
|
165 | |||
166 | /** |
||
167 | * Refresh an expired token. |
||
168 | * |
||
169 | * @param mixed $token |
||
170 | * @param Array $custom |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 3 | public function refresh($token = false, $custom = []) |
|
180 | |||
181 | /** |
||
182 | * Invalidate a token (add it to the blacklist). |
||
183 | * |
||
184 | * @param mixed $token |
||
185 | * |
||
186 | * @return boolean |
||
187 | */ |
||
188 | 3 | public function invalidate($token = false) |
|
194 | |||
195 | /** |
||
196 | * Get the token. |
||
197 | * |
||
198 | * @return boolean|string |
||
199 | */ |
||
200 | 12 | public function getToken() |
|
212 | |||
213 | /** |
||
214 | * Get the raw Payload instance. |
||
215 | * |
||
216 | * @param mixed $token |
||
217 | * |
||
218 | * @return \Tymon\JWTAuth\Payload |
||
219 | */ |
||
220 | 15 | public function getPayload($token = false) |
|
226 | |||
227 | /** |
||
228 | * Parse the token from the request. |
||
229 | * @param string $method |
||
230 | * @param string $header |
||
231 | * @param string $query |
||
232 | * @return JWTAuth |
||
233 | * @throws JWTException |
||
234 | */ |
||
235 | 15 | public function parseToken($method = 'bearer', $header = 'authorization', $query = 'token') |
|
245 | |||
246 | /** |
||
247 | * Parse token from the authorization header. |
||
248 | * |
||
249 | * @param string $header |
||
250 | * @param string $method |
||
251 | * |
||
252 | * @return false|string |
||
253 | */ |
||
254 | 15 | protected function parseAuthHeader($header = 'authorization', $method = 'bearer') |
|
264 | |||
265 | /** |
||
266 | * Create a Payload instance. |
||
267 | * |
||
268 | * @param mixed $subject |
||
269 | * @param array $customClaims |
||
270 | * |
||
271 | * @return \Tymon\JWTAuth\Payload |
||
272 | */ |
||
273 | 6 | protected function makePayload($subject, array $customClaims = []) |
|
279 | |||
280 | /** |
||
281 | * Set the identifier. |
||
282 | * |
||
283 | * @param string $identifier |
||
284 | * |
||
285 | * @return $this |
||
286 | */ |
||
287 | 3 | public function setIdentifier($identifier) |
|
293 | |||
294 | /** |
||
295 | * Get the identifier. |
||
296 | * |
||
297 | * @return string |
||
298 | */ |
||
299 | 3 | public function getIdentifier() |
|
303 | |||
304 | /** |
||
305 | * Set the token. |
||
306 | * |
||
307 | * @param string $token |
||
308 | * |
||
309 | * @return $this |
||
310 | */ |
||
311 | 27 | public function setToken($token) |
|
317 | |||
318 | /** |
||
319 | * Ensure that a token is available. |
||
320 | * |
||
321 | * @param mixed $token |
||
322 | * |
||
323 | * @return JWTAuth |
||
324 | * |
||
325 | * @throws \Tymon\JWTAuth\Exceptions\JWTException |
||
326 | */ |
||
327 | 21 | protected function requireToken($token) |
|
335 | |||
336 | /** |
||
337 | * Set the request instance. |
||
338 | * |
||
339 | * @param Request $request |
||
340 | * @return $this |
||
341 | */ |
||
342 | 3 | public function setRequest(Request $request) |
|
348 | |||
349 | /** |
||
350 | * Get the JWTManager instance. |
||
351 | * |
||
352 | * @return \Tymon\JWTAuth\JWTManager |
||
353 | */ |
||
354 | 3 | public function manager() |
|
358 | |||
359 | /** |
||
360 | * Magically call the JWT Manager. |
||
361 | * |
||
362 | * @param string $method |
||
363 | * @param array $parameters |
||
364 | * |
||
365 | * @return mixed |
||
366 | * |
||
367 | * @throws \BadMethodCallException |
||
368 | */ |
||
369 | 3 | public function __call($method, $parameters) |
|
377 | } |
||
378 |