1 | <?php |
||
21 | class TokenAuthenticator extends AbstractGuardAuthenticator |
||
22 | { |
||
23 | |||
24 | const TOKEN_HEADER = 'AUTH-TOKEN'; |
||
25 | |||
26 | /** @var UserRepository */ |
||
27 | private $userRepository; |
||
28 | |||
29 | 44 | public function __construct(UserRepository $userRepository) |
|
30 | { |
||
31 | 44 | $this->userRepository = $userRepository; |
|
32 | 44 | } |
|
33 | |||
34 | /** {@inheritDoc} */ |
||
35 | 44 | public function getCredentials(Request $request) |
|
36 | { |
||
37 | 44 | $token = $request->headers->get(self::TOKEN_HEADER); |
|
38 | |||
39 | 44 | if (!$token) { |
|
40 | return null; |
||
41 | } |
||
42 | |||
43 | return [ |
||
44 | 44 | 'token' => $token, |
|
45 | ]; |
||
46 | } |
||
47 | |||
48 | /** {@inheritDoc} */ |
||
49 | 44 | public function getUser($credentials, UserProviderInterface $userProvider) |
|
63 | |||
64 | /** {@inheritDoc} */ |
||
65 | public function start(Request $request, AuthenticationException $authException = null) |
||
75 | |||
76 | /** {@inheritDoc} */ |
||
77 | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) |
||
87 | |||
88 | /** {@inheritDoc} */ |
||
89 | 44 | public function checkCredentials($credentials, UserInterface $user) |
|
93 | |||
94 | /** {@inheritDoc} */ |
||
95 | 44 | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) |
|
99 | |||
100 | /** {@inheritDoc} */ |
||
101 | public function supportsRememberMe() |
||
105 | } |
||
106 |