1 | <?php |
||
21 | class Guard implements GuardContract |
||
22 | { |
||
23 | use GuardHelpers; |
||
24 | |||
25 | /** |
||
26 | * Default claims. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $claims = [ |
||
31 | 'aud' => 'Audience', |
||
32 | 'exp' => 'Expiration', |
||
33 | 'jti' => 'Id', |
||
34 | 'iat' => 'IssuedAt', |
||
35 | 'iss' => 'Issuer', |
||
36 | 'nbf' => 'NotBefore', |
||
37 | 'sub' => 'Subject', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * The request instance. |
||
42 | * |
||
43 | * @var \Illuminate\Http\Request |
||
44 | */ |
||
45 | protected $request; |
||
46 | |||
47 | /** |
||
48 | * @var \Framgia\Jwt\Blacklist |
||
49 | */ |
||
50 | protected $blacklist; |
||
51 | |||
52 | /** |
||
53 | * @var \Framgia\Jwt\Contracts\Signer |
||
54 | */ |
||
55 | protected $signer; |
||
56 | |||
57 | /** |
||
58 | * @var \Lcobucci\JWT\Token |
||
59 | */ |
||
60 | protected $token; |
||
61 | |||
62 | /** |
||
63 | * Create a new authentication guard. |
||
64 | * |
||
65 | * @param \Illuminate\Contracts\Auth\UserProvider $provider |
||
66 | * @param \Illuminate\Http\Request $request |
||
67 | * @param \Framgia\Jwt\Blacklist $blacklist |
||
68 | * @param \Framgia\Jwt\Contracts\Signer $signer |
||
69 | */ |
||
70 | public function __construct( |
||
82 | |||
83 | /** |
||
84 | * Get current token. |
||
85 | * |
||
86 | * @return \Lcobucci\JWT\Token |
||
87 | */ |
||
88 | public function token() |
||
96 | |||
97 | /** |
||
98 | * Refresh token expiration with same ID. |
||
99 | * |
||
100 | * @param \Lcobucci\JWT\Token|null $token |
||
101 | * @return \Lcobucci\JWT\Token |
||
102 | */ |
||
103 | public function refresh(Token $token = null) |
||
115 | |||
116 | public function setToken(Token $token) |
||
123 | |||
124 | /** |
||
125 | * Get the currently authenticated user. |
||
126 | * |
||
127 | * @return \Illuminate\Contracts\Auth\Authenticatable|null |
||
128 | */ |
||
129 | public function user() |
||
152 | |||
153 | public function setUser(Authenticatable $user) |
||
160 | |||
161 | /** |
||
162 | * Get the token for the current request. |
||
163 | * |
||
164 | * @return \Lcobucci\JWT\Token |
||
165 | */ |
||
166 | protected function getTokenForRequest() |
||
186 | |||
187 | /** |
||
188 | * Validate a user's credentials. |
||
189 | * |
||
190 | * @param array $credentials |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function validate(array $credentials = []) |
||
203 | |||
204 | /** |
||
205 | * @param array $credentials |
||
206 | * @return \Lcobucci\JWT\Token|null |
||
207 | */ |
||
208 | public function attempt(array $credentials) |
||
216 | |||
217 | /** |
||
218 | * @param Authenticatable $user |
||
219 | * @return Token |
||
220 | */ |
||
221 | public function createTokenForUser(Authenticatable $user) |
||
238 | |||
239 | /** |
||
240 | * @return bool |
||
241 | */ |
||
242 | public function logout() |
||
259 | |||
260 | /** |
||
261 | * Set the current request instance. |
||
262 | * |
||
263 | * @param \Illuminate\Http\Request $request |
||
264 | * @return $this |
||
265 | */ |
||
266 | public function setRequest(Request $request) |
||
272 | |||
273 | /** |
||
274 | * Apply claims to builder. |
||
275 | * |
||
276 | * @param array $claims |
||
277 | * @param bool $protect |
||
278 | * @param \Lcobucci\JWT\Builder|null $builder |
||
279 | * @return \Lcobucci\JWT\Builder |
||
280 | */ |
||
281 | protected function applyClaims(array $claims, $protect = false, Builder $builder = null) |
||
305 | |||
306 | /** |
||
307 | * Get token expiration timestamp. |
||
308 | * |
||
309 | * @return int |
||
310 | */ |
||
311 | protected function getExpirationTimestamp() |
||
315 | } |
||
316 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: