1 | <?php |
||
29 | class Authenticator implements LoggerAwareInterface |
||
30 | { |
||
31 | use LoggerAwareTrait; |
||
32 | |||
33 | /** |
||
34 | * The user object type. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $userType; |
||
39 | |||
40 | /** |
||
41 | * Store the user model factory instance for the current class. |
||
42 | * |
||
43 | * @var FactoryInterface |
||
44 | */ |
||
45 | private $userFactory; |
||
46 | |||
47 | /** |
||
48 | * The auth-token object type. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $tokenType; |
||
53 | |||
54 | /** |
||
55 | * Store the auth-token model factory instance for the current class. |
||
56 | * |
||
57 | * @var FactoryInterface |
||
58 | */ |
||
59 | private $tokenFactory; |
||
60 | |||
61 | /** |
||
62 | * @param array $data Class dependencies. |
||
63 | */ |
||
64 | public function __construct(array $data) |
||
72 | |||
73 | /** |
||
74 | * Determine if the current user is authenticated. |
||
75 | * |
||
76 | * The user is authenticated via _session ID_ or _auth token_. |
||
77 | * |
||
78 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
79 | * or NULL if not authenticated. |
||
80 | */ |
||
81 | public function authenticate() |
||
95 | |||
96 | /** |
||
97 | * Attempt to authenticate a user using the given credentials. |
||
98 | * |
||
99 | * @param string $username Username, part of necessary credentials. |
||
100 | * @param string $password Password, part of necessary credentials. |
||
101 | * @param string|null $key Optional property (key) to use for the username. Defaults to actual object's key. |
||
102 | * @throws InvalidArgumentException If username or password are invalid or empty. |
||
103 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
104 | * or NULL if not authenticated. |
||
105 | */ |
||
106 | public function authenticateByPassword($username, $password, $key=null) |
||
164 | |||
165 | /** |
||
166 | * Retrieve the user object type. |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | protected function userType() |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Retrieve the user model factory. |
||
178 | * |
||
179 | * @throws RuntimeException If the model factory was not previously set. |
||
180 | * @return FactoryInterface |
||
181 | */ |
||
182 | protected function userFactory() |
||
186 | |||
187 | /** |
||
188 | * Retrieve the auth-token object type. |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | protected function tokenType() |
||
196 | |||
197 | /** |
||
198 | * Retrieve the auth-token model factory. |
||
199 | * |
||
200 | * @throws RuntimeException If the token factory was not previously set. |
||
201 | * @return FactoryInterface |
||
202 | */ |
||
203 | protected function tokenFactory() |
||
207 | |||
208 | /** |
||
209 | * Set the user object type (model). |
||
210 | * |
||
211 | * @param string $type The user object type. |
||
212 | * @throws InvalidArgumentException If the user object type parameter is not a string. |
||
213 | * @return void |
||
214 | */ |
||
215 | private function setUserType($type) |
||
225 | |||
226 | /** |
||
227 | * Set a user model factory. |
||
228 | * |
||
229 | * @param FactoryInterface $factory The factory used to create new user instances. |
||
230 | * @return void |
||
231 | */ |
||
232 | private function setUserFactory(FactoryInterface $factory) |
||
236 | |||
237 | /** |
||
238 | * Set the authorization token type (model). |
||
239 | * |
||
240 | * @param string $type The auth-token object type. |
||
241 | * @throws InvalidArgumentException If the token object type parameter is not a string. |
||
242 | * @return void |
||
243 | */ |
||
244 | private function setTokenType($type) |
||
254 | |||
255 | /** |
||
256 | * Set a model factory for token-based authentication. |
||
257 | * |
||
258 | * @param FactoryInterface $factory The factory used to create new auth-token instances. |
||
259 | * @return void |
||
260 | */ |
||
261 | private function setTokenFactory(FactoryInterface $factory) |
||
265 | |||
266 | /** |
||
267 | * Attempt to authenticate a user using their session ID. |
||
268 | * |
||
269 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
270 | * or NULL if not authenticated. |
||
271 | */ |
||
272 | private function authenticateBySession() |
||
286 | |||
287 | /** |
||
288 | * Attempt to authenticate a user using their auth token. |
||
289 | * |
||
290 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
291 | * or NULL if not authenticated. |
||
292 | */ |
||
293 | private function authenticateByToken() |
||
321 | } |
||
322 |