requestAuthenticationCode() public method

Request and validate authentication code.
public requestAuthenticationCode ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context ) : Response | null
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
return Symfony\Component\HttpFoundation\Response | null
コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Listen for request events
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 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->securityContext->getToken();
     if (!$this->isTokenSupported($token)) {
         return;
     }
     // Forward to two-factor provider
     // Providers can create a response object
     $context = new AuthenticationContext($request, $token);
     $response = $this->authHandler->requestAuthenticationCode($context);
     // Set the response (if there is one)
     if ($response instanceof Response) {
         $event->setResponse($response);
     }
 }