/** * @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); }
/** * Test if prefix is not auto-set when it is already set. */ public function testPrefixIsNotSetIfAlreadySet() { $this->assertEquals('first_', $this->cookies->prefix('first_')->getPrefix()); $this->assertEquals('first_', $this->cookies->configureFromUrl('https://activecollab.com/projects')->getPrefix()); }
/** * Test if remove unsets prefixed cookie value. */ public function testRemove() { $this->assertTrue($this->cookies->exists($this->request, 'our_cookie')); list($this->request, $this->response) = $this->cookies->remove($this->request, $this->response, 'our_cookie'); $this->assertFalse($this->cookies->exists($this->request, 'our_cookie')); }