Inheritance: implements Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
 /**
  * Ask for email authentication code
  *
  * @param  \Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContext $context
  * @return \Symfony\Component\HttpFoundation\Response|null
  */
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $user = $context->getUser();
     $request = $context->getRequest();
     $session = $context->getSession();
     // Display and process form
     $authCode = $request->get($this->authCodeParameter);
     if ($authCode !== null) {
         if ($this->authenticator->checkCode($user, $authCode)) {
             $context->setAuthenticated(true);
             return new RedirectResponse($request->getUri());
         } else {
             $session->getFlashBag()->set("two_factor", "scheb_two_factor.code_invalid");
         }
     }
     // Force authentication code dialog
     return $this->templating->renderResponse($this->formTemplate, array('useTrustedOption' => $context->useTrustedOption()));
 }
 /**
  * Call TwoFactorProviderRegistry, set trusted computer cookie if requested
  *
  * @param  \Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContext $context
  * @return \Symfony\Component\HttpFoundation\Response|null
  */
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $request = $context->getRequest();
     $user = $context->getUser();
     $context->setUseTrustedOption($this->useTrustedOption($user));
     // Set trusted flag
     $response = $this->authHandler->requestAuthenticationCode($context);
     // On response validate if trusted cookie should be set
     if ($response instanceof Response) {
         // Set trusted cookie
         if ($context->isAuthenticated() && $request->get($this->trustedName)) {
             $cookie = $this->cookieManager->createTrustedCookie($request, $user);
             $response->headers->setCookie($cookie);
         }
         return $response;
     }
     return null;
 }
 /**
  * Iterate over two-factor providers and ask for two-factor authentcation.
  * Each provider can return a response. The first response will be returned.
  *
  * @param  \Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContext $context
  * @return \Symfony\Component\HttpFoundation\Response|null
  */
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $token = $context->getToken();
     // Iterate over two-factor providers and ask for completion
     foreach ($this->providers as $providerName => $provider) {
         if ($this->flagManager->isNotAuthenticated($providerName, $token)) {
             $response = $provider->requestAuthenticationCode($context);
             // Set authentication completed
             if ($context->isAuthenticated()) {
                 $this->flagManager->setComplete($providerName, $token);
             }
             // Return response
             if ($response instanceof Response) {
                 return $response;
             }
         }
     }
     return null;
 }
 /**
  * requestAuthenticationCode
  * @param AuthenticationContext $context
  * @return \Symfony\Component\HttpFoundation\Response|null
  **/
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $user = $context->getUser();
     $request = $context->getRequest();
     $session = $context->getSession();
     $authData = $request->get($this->authCodeParameter);
     if (null !== $authData) {
         if ($this->authenticator->checkRequest($user, json_decode($session->get('u2f_authentication')), json_decode($authData))) {
             $context->setAuthenticated(true);
             return new RedirectResponse($request->getUri());
         } else {
             $session->getFlashBag()->set('two_factor', 'r_u2f_two_factor.code_invalid');
         }
     }
     $authenticationData = json_encode($this->authenticator->generateRequest($user), JSON_UNESCAPED_SLASHES);
     $session->set('u2f_authentication', $authenticationData);
     return $this->templating->renderResponse($this->formTemplate, array('authenticationData' => $authenticationData, 'useTrustedOption' => $context->useTrustedOption()));
 }
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $user = $context->getUser();
     $request = $context->getRequest();
     $session = $context->getSession();
     // Display and process form
     $authCode = $request->get($this->authCodeParameter);
     if ($authCode !== null) {
         $result = $this->authenticator->checkCode($user, $authCode);
         if ($result) {
             //get the inwebo alias
             $alias = $result['alias'];
             //Persist the alias to the database to be used in case we do 2FA only once
             $this->codeHandler->getAndPersist($user, $alias);
             $context->setAuthenticated(true);
             return new RedirectResponse($request->getUri());
         } else {
             $session->getFlashBag()->set("two_factor", "scheb_two_factor.code_invalid");
         }
     }
     //die();
     // Force authentication code dialog
     return $this->templating->renderResponse($this->formTemplate, array('useTrustedOption' => $context->useTrustedOption()));
 }
 /**
  * @test
  */
 public function setAuthenticated_wasNotAuthenticated_becomeAuthenticated()
 {
     $this->authContext->setAuthenticated(true);
     $returnValue = $this->authContext->isAuthenticated();
     $this->assertTrue($returnValue);
 }