Scheb\TwoFactorBundle\Security\TwoFactor\EventListener\RequestListener::onCoreRequest PHP Method

onCoreRequest() public method

Listen for request events.
public onCoreRequest ( GetResponseEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseEvent
    public function onCoreRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        // Exclude path
        if ($this->excludePattern !== null && preg_match('#' . $this->excludePattern . '#', $request->getPathInfo())) {
            return;
        }
        // Check if security token is supported
        $token = $this->tokenStorage->getToken();
        if (!$this->isTokenSupported($token)) {
            return;
        }
        // Forward to two-factor provider
        // Providers can create a response object
        $context = $this->authenticationContextFactory->create($request, $token);
        $response = $this->authHandler->requestAuthenticationCode($context);
        // Set the response (if there is one)
        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }

Usage Example

 /**
  * @test
  */
 public function onCoreRequest_pathExcluded_notRequestAuthenticationCode()
 {
     $event = $this->createEvent("/exclude/someFile");
     $token = $this->createSupportedSecurityToken();
     $this->stubSecurityContext($token);
     //Expect TwoFactorProvider to be called
     $this->authHandler->expects($this->never())->method("requestAuthenticationCode");
     $this->listener->onCoreRequest($event);
 }
All Usage Examples Of Scheb\TwoFactorBundle\Security\TwoFactor\EventListener\RequestListener::onCoreRequest