<?php
namespace ApiBundle\EventListener;
use ApiBundle\Security\Firewall\XAuthTokenAuthenticationListener;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
use AppBundle\Component\Track\UserOnlineTrack;
class AuthenticateListener
{
private $container;
private $userOnlineTrack;
public function __construct(ContainerInterface $container, UserOnlineTrack $userOnlineTrack)
{
$this->container = $container;
$this->userOnlineTrack = $userOnlineTrack;
}
public function onAuthenticate(AuthenticationEvent $event)
{
$request = $this->container->get('request_stack')->getMainRequest();
$authToken = $request->headers->get(XAuthTokenAuthenticationListener::TOKEN_HEADER);
if (!empty($authToken)) {
$this->userOnlineTrack->track($request->headers->get(XAuthTokenAuthenticationListener::TOKEN_HEADER));
}
}
}