Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedFilter::beginAuthentication PHP Method

beginAuthentication() public method

Check if user is on a trusted computer, otherwise call TwoFactorProviderRegistry.
public beginAuthentication ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context )
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
    public function beginAuthentication(AuthenticationContextInterface $context)
    {
        $request = $context->getRequest();
        $user = $context->getUser();
        $context->setUseTrustedOption($this->useTrustedOption);
        // Skip two-factor authentication on trusted computers
        if ($context->useTrustedOption() && $this->cookieManager->isTrustedComputer($request, $user)) {
            return;
        }
        $this->authHandler->beginAuthentication($context);
    }

Usage Example

 /**
  * @test
  */
 public function beginAuthentication_notTrustedComputer_callAuthenticationHandler()
 {
     $context = $this->getAuthenticationContext();
     //Stub the TrustedCookieManager
     $this->cookieManager->expects($this->any())->method('isTrustedComputer')->willReturn(false);
     //Mock the authentication handler
     $this->authHandler->expects($this->once())->method('beginAuthentication')->with($context);
     $this->trustedFilter->beginAuthentication($context);
 }