Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\TwoFactorProvider::beginAuthentication PHP Method

beginAuthentication() public method

Begin Google authentication process.
public beginAuthentication ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context ) : boolean
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
return boolean
    public function beginAuthentication(AuthenticationContextInterface $context)
    {
        // Check if user can do email authentication
        $user = $context->getUser();
        return $user instanceof TwoFactorInterface && $user->getGoogleAuthenticatorSecret();
    }

Usage Example

 /**
  * @test
  */
 public function beginAuthentication_interfaceNotImplemented_returnFalse()
 {
     $user = new \stdClass();
     //Any class without TwoFactorInterface
     $context = $this->getAuthenticationContext($user);
     $returnValue = $this->provider->beginAuthentication($context);
     $this->assertFalse($returnValue);
 }