Esempio n. 1
0
 /**
  * Test if set adds prefixed cookied value.
  */
 public function testSet()
 {
     $this->assertFalse($this->cookies->exists($this->request, 'new_cookie'));
     list($this->request, $this->response) = $this->cookies->set($this->request, $this->response, 'new_cookie', 'new_cookie_value');
     $this->assertTrue($this->cookies->exists($this->request, 'new_cookie'));
     $this->assertSame('new_cookie_value', $this->cookies->get($this->request, 'new_cookie'));
 }
 /**
  * @expectedException \ActiveCollab\Authentication\Exception\InvalidAuthenticationRequestException
  * @expectedExceptionMessage You can not be authenticated with more than one authentication method
  */
 public function testExceptionOnMultipleIds()
 {
     /** @var ServerRequestInterface $request */
     /** @var ResponseInterface $response */
     list($request, $response) = $this->cookies->set($this->request, $this->response, $this->browser_session_cookie_name, 'my-session-id');
     /** @var ServerRequestInterface $request */
     $request = $request->withHeader('Authorization', 'Bearer awesome-token');
     call_user_func(new Authentication([$this->browser_session_adapter, $this->token_bearer_adapter]), $request, $response);
 }
 /**
  * {@inheritdoc}
  */
 public function applyTo(ServerRequestInterface $request, ResponseInterface $response, TransportInterface $transport)
 {
     // Extend session
     if ($transport instanceof AuthenticationTransportInterface) {
         $authenticated_with = $transport->getAuthenticatedWith();
         if (!$authenticated_with instanceof SessionInterface) {
             throw new InvalidArgumentException('Only user sessions are supported');
         }
         $authenticated_with->extendSession();
         list($request, $response) = $this->cookies->set($request, $response, $this->session_cookie_name, $authenticated_with->getSessionId(), ['ttl' => $authenticated_with->getSessionTtl(), 'http_only' => true]);
         // Log in
     } elseif ($transport instanceof AuthorizationTransportInterface) {
         $authenticated_with = $transport->getAuthenticatedWith();
         if (!$authenticated_with instanceof SessionInterface) {
             throw new InvalidArgumentException('Only user sessions are supported');
         }
         list($request, $response) = $this->cookies->set($request, $response, $this->session_cookie_name, $authenticated_with->getSessionId(), ['ttl' => $authenticated_with->getSessionTtl(), 'http_only' => true]);
         // Log out or clean-up
     } elseif ($transport instanceof DeauthenticationTransportInterface || $transport instanceof CleanUpTransportInterface) {
         list($request, $response) = $this->cookies->remove($request, $response, $this->session_cookie_name);
     }
     return parent::applyTo($request, $response, $transport);
 }
 /**
  * @param string $name
  * @param mixed  $value
  */
 protected function setCookie($name, $value)
 {
     list($this->request, $this->response) = $this->cookies->set($this->request, $this->response, $name, $value);
 }