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 | public function login(Authenticatable $user) |
||
165 | |||
166 | /** |
||
167 | * Get the token for the current request. |
||
168 | * |
||
169 | * @return \Lcobucci\JWT\Token |
||
170 | */ |
||
171 | protected function getTokenForRequest() |
||
191 | |||
192 | /** |
||
193 | * Validate a user's credentials. |
||
194 | * |
||
195 | * @param array $credentials |
||
196 | * @return bool |
||
197 | */ |
||
198 | public function validate(array $credentials = []) |
||
208 | |||
209 | /** |
||
210 | * @param array $credentials |
||
211 | * @return \Lcobucci\JWT\Token|null |
||
212 | */ |
||
213 | public function attempt(array $credentials) |
||
221 | |||
222 | /** |
||
223 | * @param Authenticatable $user |
||
224 | * @return Token |
||
225 | */ |
||
226 | public function createTokenForUser(Authenticatable $user) |
||
243 | |||
244 | /** |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function logout() |
||
264 | |||
265 | /** |
||
266 | * Set the current request instance. |
||
267 | * |
||
268 | * @param \Illuminate\Http\Request $request |
||
269 | * @return $this |
||
270 | */ |
||
271 | public function setRequest(Request $request) |
||
277 | |||
278 | /** |
||
279 | * Apply claims to builder. |
||
280 | * |
||
281 | * @param array $claims |
||
282 | * @param bool $protect |
||
283 | * @param \Lcobucci\JWT\Builder|null $builder |
||
284 | * @return \Lcobucci\JWT\Builder |
||
285 | */ |
||
286 | protected function applyClaims(array $claims, $protect = false, Builder $builder = null) |
||
310 | |||
311 | /** |
||
312 | * Get token expiration timestamp. |
||
313 | * |
||
314 | * @return int |
||
315 | */ |
||
316 | protected function getExpirationTimestamp() |
||
320 | } |
||
321 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: