/** * Iterate over two-factor providers and ask for two-factor authentication. * Each provider can return a response. The first response will be returned. * * @param AuthenticationContextInterface $context * * @return Response|null */ public function requestAuthenticationCode(AuthenticationContextInterface $context) { $token = $context->getToken(); // Iterate over two-factor providers and ask for completion /** @var TwoFactorProviderInterface $provider */ foreach ($this->providers as $providerName => $provider) { if ($this->flagManager->isNotAuthenticated($providerName, $token)) { $response = $provider->requestAuthenticationCode($context); // Set authentication completed if ($context->isAuthenticated()) { $this->eventDispatcher->dispatch(TwoFactorAuthenticationEvents::SUCCESS, new TwoFactorAuthenticationEvent()); $this->flagManager->setComplete($providerName, $token); } else { if ($context->getRequest()->get($this->authRequestParameter) !== null) { $this->eventDispatcher->dispatch(TwoFactorAuthenticationEvents::FAILURE, new TwoFactorAuthenticationEvent()); } } // Return response if ($response instanceof Response) { return $response; } } } return null; }
/** * Call TwoFactorProviderRegistry, set trusted computer cookie if requested. * * @param AuthenticationContextInterface $context * * @return Response|null */ public function requestAuthenticationCode(AuthenticationContextInterface $context) { $request = $context->getRequest(); $user = $context->getUser(); $context->setUseTrustedOption($this->useTrustedOption); // 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() && $context->useTrustedOption() && $request->get($this->trustedName)) { $cookie = $this->cookieManager->createTrustedCookie($request, $user); $response->headers->setCookie($cookie); } return $response; } return null; }
/** * Ask for email authentication code. * * @param AuthenticationContextInterface $context * * @return Response|null */ public function requestAuthenticationCode(AuthenticationContextInterface $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()); } $session->getFlashBag()->set('two_factor', 'scheb_two_factor.code_invalid'); } // Force authentication code dialog return $this->renderer->render($context); }
public function render(AuthenticationContextInterface $context) { return $this->templating->renderResponse($this->formTemplate, array('useTrustedOption' => $context->useTrustedOption())); }