Scheb\TwoFactorBundle\Security\TwoFactor\EventListener\InteractiveLoginListener::onSecurityInteractiveLogin PHP Method

onSecurityInteractiveLogin() public method

Listen for successful login events.
public onSecurityInteractiveLogin ( Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event )
$event Symfony\Component\Security\Http\Event\InteractiveLoginEvent
    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        $request = $event->getRequest();
        // Skip two-factor authentication for whitelisted IPs
        if (in_array($request->getClientIp(), $this->ipWhitelist)) {
            return;
        }
        // Check if security token is supported
        $token = $event->getAuthenticationToken();
        if (!$this->isTokenSupported($token)) {
            return;
        }
        // Forward to two-factor providers
        // They decide if they will do two-factor authentication
        $context = $this->authenticationContextFactory->create($request, $token);
        $this->authHandler->beginAuthentication($context);
    }

Usage Example

 /**
  * @test
  */
 public function onSecurityInteractiveLogin_tokenClassNotSupported_doNothing()
 {
     $token = $this->getMock("Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface");
     $event = $this->createEvent($token);
     //Expect TwoFactorProvider not to be called
     $this->authHandler->expects($this->never())->method("beginAuthentication");
     $this->listener->onSecurityInteractiveLogin($event);
 }
All Usage Examples Of Scheb\TwoFactorBundle\Security\TwoFactor\EventListener\InteractiveLoginListener::onSecurityInteractiveLogin