1 | <?php |
||
9 | class PayloadFactory |
||
10 | { |
||
11 | /** |
||
12 | * @var \Tymon\JWTAuth\Claims\Factory |
||
13 | */ |
||
14 | protected $claimFactory; |
||
15 | |||
16 | /** |
||
17 | * @var \Illuminate\Http\Request |
||
18 | */ |
||
19 | protected $request; |
||
20 | |||
21 | /** |
||
22 | * @var \Tymon\JWTAuth\Validators\PayloadValidator |
||
23 | */ |
||
24 | protected $validator; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $ttl = 60; |
||
30 | |||
31 | /** |
||
32 | * @var boolean |
||
33 | */ |
||
34 | protected $refreshFlow = false; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $defaultClaims = ['iss', 'iat', 'exp', 'nbf', 'jti']; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $claims = []; |
||
45 | |||
46 | /** |
||
47 | * @param \Tymon\JWTAuth\Claims\Factory $claimFactory |
||
48 | * @param \Illuminate\Http\Request $request |
||
49 | * @param \Tymon\JWTAuth\Validators\PayloadValidator $validator |
||
50 | */ |
||
51 | 12 | public function __construct(Factory $claimFactory, Request $request, PayloadValidator $validator) |
|
57 | |||
58 | /** |
||
59 | * Create the Payload instance |
||
60 | * |
||
61 | * @param array $customClaims |
||
62 | * @return \Tymon\JWTAuth\Payload |
||
63 | */ |
||
64 | 9 | public function make(array $customClaims = []) |
|
70 | |||
71 | /** |
||
72 | * Add an array of claims to the Payload |
||
73 | * |
||
74 | * @param array $claims |
||
75 | * @return $this |
||
76 | */ |
||
77 | 9 | public function addClaims(array $claims) |
|
85 | |||
86 | /** |
||
87 | * Add a claim to the Payload |
||
88 | * |
||
89 | * @param string $name |
||
90 | * @param mixed $value |
||
91 | * @return $this |
||
92 | */ |
||
93 | 9 | public function addClaim($name, $value) |
|
99 | |||
100 | /** |
||
101 | * Build the default claims |
||
102 | * |
||
103 | * @param array $customClaims |
||
104 | * @return $this |
||
105 | */ |
||
106 | 9 | protected function buildClaims(array $customClaims) |
|
119 | |||
120 | /** |
||
121 | * Build out the Claim DTO's |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | 9 | public function resolveClaims() |
|
134 | |||
135 | /** |
||
136 | * Set the Issuer (iss) claim |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 9 | public function iss() |
|
144 | |||
145 | /** |
||
146 | * Set the Issued At (iat) claim |
||
147 | * |
||
148 | * @return int |
||
149 | */ |
||
150 | 6 | public function iat() |
|
154 | |||
155 | /** |
||
156 | * Set the Expiration (exp) claim |
||
157 | * |
||
158 | * @return int |
||
159 | */ |
||
160 | 9 | public function exp() |
|
164 | |||
165 | /** |
||
166 | * Set the Not Before (nbf) claim |
||
167 | * |
||
168 | * @return int |
||
169 | */ |
||
170 | 9 | public function nbf() |
|
174 | |||
175 | /** |
||
176 | * Set a unique id (jti) for the token |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | 6 | protected function jti() |
|
187 | |||
188 | /** |
||
189 | * Set the token ttl (in minutes) |
||
190 | * |
||
191 | * @param int $ttl |
||
192 | * @return $this |
||
193 | */ |
||
194 | 3 | public function setTTL($ttl) |
|
200 | |||
201 | /** |
||
202 | * Get the token ttl |
||
203 | * |
||
204 | * @return int |
||
205 | */ |
||
206 | 3 | public function getTTL() |
|
210 | |||
211 | /** |
||
212 | * Set the refresh flow |
||
213 | * |
||
214 | * @param boolean $refreshFlow |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function setRefreshFlow($refreshFlow = true) |
||
223 | |||
224 | /** |
||
225 | * Magically add a claim |
||
226 | * |
||
227 | * @param string $method |
||
228 | * @param array $parameters |
||
229 | * @return PayloadFactory |
||
230 | * @throws \BadMethodCallException |
||
231 | */ |
||
232 | 6 | public function __call($method, $parameters) |
|
238 | } |
||
239 |