Skip to content

Instantly share code, notes, and snippets.

@chalasr
Last active January 11, 2020 11:23
Show Gist options
  • Save chalasr/69ad35c11e38b8cc717f to your computer and use it in GitHub Desktop.
Save chalasr/69ad35c11e38b8cc717f to your computer and use it in GitHub Desktop.
FOSUserBundle Login Authentication Success Handler example.
<?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);
}
}
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
services:
# ...
app.authentication_success_handler:
class: AppBundle\EventListener\AuthenticationSuccessHandler
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onSecurityInteractiveLogin }
@Jules59
Copy link

Jules59 commented Jul 24, 2018

coj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment