1 | <?php |
||
20 | class JWTGuard implements Guard |
||
21 | { |
||
22 | use GuardHelpers; |
||
23 | |||
24 | /** |
||
25 | * The user we last attempted to retrieve. |
||
26 | * |
||
27 | * @var \Illuminate\Contracts\Auth\Authenticatable |
||
28 | */ |
||
29 | protected $lastAttempted; |
||
30 | |||
31 | /** |
||
32 | * The JWTAuth instance. |
||
33 | * |
||
34 | * @var \Tymon\JWTAuth\JWTAuth |
||
35 | */ |
||
36 | protected $auth; |
||
37 | |||
38 | /** |
||
39 | * The request instance. |
||
40 | * |
||
41 | * @var \Illuminate\Http\Request |
||
42 | */ |
||
43 | protected $request; |
||
44 | |||
45 | public function __construct(JWTAuth $auth, UserProvider $provider, Request $request) |
||
51 | |||
52 | /** |
||
53 | * Get the currently authenticated user. |
||
54 | * |
||
55 | * @return \Illuminate\Contracts\Auth\Authenticatable|null |
||
56 | */ |
||
57 | public function user() |
||
71 | |||
72 | /** |
||
73 | * Validate a user's credentials. |
||
74 | * |
||
75 | * @param array $credentials |
||
76 | * |
||
77 | * @return boolean |
||
78 | */ |
||
79 | public function validate(array $credentials = []) |
||
83 | |||
84 | /** |
||
85 | * Attempt to authenticate the user using the given credentials and return the token. |
||
86 | * |
||
87 | * @param array $credentials |
||
88 | * |
||
89 | * @return boolean |
||
90 | */ |
||
91 | public function attempt(array $credentials = [], $login = true) |
||
107 | |||
108 | /** |
||
109 | * Logout the user, thus invalidating the token. |
||
110 | * |
||
111 | * @param boolean $forceForever |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function logout($forceForever = false) |
||
122 | |||
123 | /** |
||
124 | * Refresh the token |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | public function refresh() |
||
132 | |||
133 | /** |
||
134 | * Create a new token by User id |
||
135 | * |
||
136 | * @param mixed $id |
||
137 | * |
||
138 | * @return string|null |
||
139 | */ |
||
140 | public function tokenById($id) |
||
148 | |||
149 | /** |
||
150 | * Log a user into the application using their credentials. |
||
151 | * |
||
152 | * @param array $credentials |
||
153 | * |
||
154 | * @return boolean |
||
155 | */ |
||
156 | public function once(array $credentials = []) |
||
166 | |||
167 | /** |
||
168 | * Log the given User into the application. |
||
169 | * |
||
170 | * @param mixed $id |
||
171 | * |
||
172 | * @return boolean |
||
173 | */ |
||
174 | public function onceUsingId($id) |
||
184 | |||
185 | /** |
||
186 | * Alias for onceUsingId |
||
187 | * |
||
188 | * @param mixed $id |
||
189 | * |
||
190 | * @return boolean |
||
191 | */ |
||
192 | public function byId($id) |
||
196 | |||
197 | /** |
||
198 | * Get the raw Payload instance. |
||
199 | * |
||
200 | * @return \Tymon\JWTAuth\Payload |
||
201 | */ |
||
202 | public function getPayload() |
||
206 | |||
207 | /** |
||
208 | * Set the token. |
||
209 | * |
||
210 | * @param Token|string $token |
||
211 | * |
||
212 | * @return JWTGuard |
||
213 | */ |
||
214 | public function setToken($token) |
||
220 | |||
221 | /** |
||
222 | * Get the user provider used by the guard. |
||
223 | * |
||
224 | * @return \Illuminate\Contracts\Auth\UserProvider |
||
225 | */ |
||
226 | public function getProvider() |
||
230 | |||
231 | /** |
||
232 | * Set the user provider used by the guard. |
||
233 | * |
||
234 | * @param \Illuminate\Contracts\Auth\UserProvider $provider |
||
235 | * |
||
236 | * @return void |
||
237 | */ |
||
238 | public function setProvider(UserProvider $provider) |
||
242 | |||
243 | /** |
||
244 | * Return the currently cached user. |
||
245 | * |
||
246 | * @return \Illuminate\Contracts\Auth\Authenticatable|null |
||
247 | */ |
||
248 | public function getUser() |
||
252 | |||
253 | /** |
||
254 | * Get the current request instance. |
||
255 | * |
||
256 | * @return \Symfony\Component\HttpFoundation\Request |
||
257 | */ |
||
258 | public function getRequest() |
||
262 | |||
263 | /** |
||
264 | * Set the current request instance. |
||
265 | * |
||
266 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
267 | * |
||
268 | * @return $this |
||
269 | */ |
||
270 | public function setRequest(Request $request) |
||
276 | |||
277 | /** |
||
278 | * Get the last user we attempted to authenticate. |
||
279 | * |
||
280 | * @return \Illuminate\Contracts\Auth\Authenticatable |
||
281 | */ |
||
282 | public function getLastAttempted() |
||
286 | |||
287 | /** |
||
288 | * Determine if the user matches the credentials. |
||
289 | * |
||
290 | * @param mixed $user |
||
291 | * @param array $credentials |
||
292 | * |
||
293 | * @return boolean |
||
294 | */ |
||
295 | protected function hasValidCredentials($user, $credentials) |
||
299 | |||
300 | /** |
||
301 | * Ensure that a token is available in the request |
||
302 | * |
||
303 | * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
304 | * |
||
305 | * @return \Tymon\JWTAuth\JWTAuth |
||
306 | */ |
||
307 | protected function requireToken() |
||
315 | } |
||
316 |