Skip to content

Instantly share code, notes, and snippets.

@naitsirch
naitsirch / AjaxAuthenticationListener.php
Last active Aug 29, 2015 — forked from xanf/AjaxAuthenticationListener.php
How to register an Symfony event handler to prevent JSON/AJAX requests to be redirected
View AjaxAuthenticationListener.php
<?php
namespace Acme\Bundle\MyBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class AjaxAuthenticationListener
{