Skip to content

Instantly share code, notes, and snippets.

@texpert
Created November 10, 2016 12:08
Show Gist options
  • Save texpert/99031336dd0ad0d6aefb70887ed6a00e to your computer and use it in GitHub Desktop.
Save texpert/99031336dd0ad0d6aefb70887ed6a00e to your computer and use it in GitHub Desktop.
src/AppBundle/EventListener/LogoutListener.php:
//
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
class LogoutListener implements LogoutSuccessHandlerInterface
{
public function onLogoutSuccess(Request $request)
{
return new RedirectResponse('http://logout@'.$request->getHttpHost());
}
}
app/config/services.yml:
//
services:
logout_listener:
class: AppBundle\EventListener\LogoutListener
app/config/routing.yml:
//
logout:
path: /logout
app/config/security.yml:
//
security:
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
# activate different ways to authenticate
http_basic: ~
# http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
logout:
path: /logout
target: /
success_handler: logout_listener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment