1 | <?php |
||
37 | class RefreshTokenAuthenticator extends RefreshTokenAuthenticatorBase implements AuthenticationFailureHandlerInterface |
||
38 | { |
||
39 | public function createToken(Request $request, $providerKey) |
||
40 | { |
||
41 | $refreshTokenString = RequestRefreshToken::getRefreshToken($request); |
||
42 | |||
43 | return new PreAuthenticatedToken( |
||
44 | '', |
||
45 | $refreshTokenString, |
||
46 | $providerKey |
||
47 | ); |
||
48 | } |
||
49 | |||
50 | public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey) |
||
51 | { |
||
52 | if (!$userProvider instanceof RefreshTokenProvider) { |
||
53 | throw new \InvalidArgumentException( |
||
54 | sprintf( |
||
55 | 'The user provider must be an instance of RefreshTokenProvider (%s was given).', |
||
56 | get_class($userProvider) |
||
57 | ) |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | $refreshToken = $token->getCredentials(); |
||
62 | $username = $userProvider->getUsernameForRefreshToken($refreshToken); |
||
63 | |||
64 | if (!$username) { |
||
65 | throw new AuthenticationException( |
||
66 | sprintf('Refresh token "%s" does not exist.', $refreshToken) |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | $user = $userProvider->loadUserByUsername($username); |
||
71 | |||
72 | return new PreAuthenticatedToken( |
||
73 | $user, |
||
74 | $refreshToken, |
||
75 | $providerKey, |
||
76 | $user->getRoles() |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | 1 | public function supportsToken(TokenInterface $token, $providerKey) |
|
84 | |||
85 | 1 | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) |
|
89 | } |
||
90 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.