urlGenerator = $urlGenerator; $this->csrfTokenManager = $csrfTokenManager; } public function supports(Request $request) { return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST'); } public function getCredentials(Request $request) { $credentials = [ '' => $request->request->get(''), 'password' => $request->request->get('password'), 'csrf_token' => $request->request->get('_csrf_token'), ]; $request->getSession()->set( Security::LAST_USERNAME, $credentials[''] ); return $credentials; } public function getUser($credentials, UserProviderInterface $userProvider) { $token = new CsrfToken('authenticate', $credentials['csrf_token']); if (!$this->csrfTokenManager->isTokenValid($token)) { throw new InvalidCsrfTokenException(); } // Load / create our user however you need. // You can do this by calling the user provider, or with custom logic here. $user = $userProvider->loadUserByUsername($credentials['']); if (!$user) { throw new UsernameNotFoundException(' could not be found.'); } return $user; } public function checkCredentials($credentials, UserInterface $user) { // Check the user's password or other credentials and return true or false // If there are no credentials to check, you can just return true throw new \Exception('TODO: check the credentials inside '.__FILE__); } public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) { if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) { return new RedirectResponse($targetPath); } // For example : return new RedirectResponse($this->urlGenerator->generate('some_route')); throw new \Exception('TODO: provide a valid redirect inside '.__FILE__); } protected function getLoginUrl() { return $this->urlGenerator->generate(self::LOGIN_ROUTE); } }