Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedFilter::requestAuthenticationCode PHP Метод

requestAuthenticationCode() публичный Метод

Call TwoFactorProviderRegistry, set trusted computer cookie if requested.
public requestAuthenticationCode ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context ) : Response | null
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
Результат Symfony\Component\HttpFoundation\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;
    }

Usage Example

Пример #1
0
 /**
  * @test
  */
 public function requestAuthenticationCode_shouldCheckIfTrustedIsAllowedByContext()
 {
     $context = $this->getAuthenticationContext();
     $context->expects($this->once())->method('isAuthenticated')->willReturn(true);
     $context->expects($this->once())->method('useTrustedOption')->willReturn(false);
     $this->authHandler->expects($this->once())->method('requestAuthenticationCode')->with($context)->willReturn(new Response('<form></form>'));
     $this->cookieManager->expects($this->never())->method('createTrustedCookie');
     $returnValue = $this->trustedFilter->requestAuthenticationCode($context);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $returnValue);
 }
All Usage Examples Of Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedFilter::requestAuthenticationCode