Last active
January 11, 2020 11:23
-
-
Save chalasr/69ad35c11e38b8cc717f to your computer and use it in GitHub Desktop.
FOSUserBundle Login Authentication Success Handler example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\EventListener; | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpFoundation\RedirectResponse; | |
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | |
class AuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface | |
{ | |
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) | |
{ | |
$token = $event->getAuthenticationToken(); | |
$request = $event->getRequest(); | |
$this->onAuthenticationSuccess($request, $token); | |
} | |
public function onAuthenticationSuccess(Request $request, TokenInterface $token) | |
{ | |
return new RedirectResponse($referer); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
# ... | |
firewalls: | |
# ... | |
user: | |
pattern: /(.*) | |
form_login: | |
provider: fos_userbundle | |
login_path: /login | |
use_forward: false | |
check_path: /login_check | |
failure_path: null | |
success_handler: app.authentication_success_handler | |
logout: | |
path: /logout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
# ... | |
app.authentication_success_handler: | |
class: AppBundle\EventListener\AuthenticationSuccessHandler | |
tags: | |
- { name: kernel.event_listener, event: security.interactive_login, method: onSecurityInteractiveLogin } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
coj