public function createSession($login, $password)
{
$this->createRequest('post', '/user/sessions');
$this->setHeaderWithObject('accept', 'Session');
$this->setHeaderWithObject('content-type', 'SessionInput');
$this->makeObject('SessionInput');
$this->setFieldToValue('login', $login);
$this->setFieldToValue('password', $password);
$this->sendRequest();
$this->userSession = $this->getResponseObject();
if (!$this->userSession instanceof \eZ\Publish\Core\REST\Server\Values\UserSession) {
if ($this->userSession instanceof \eZ\Publish\Core\REST\Client\Values\ErrorMessage) {
$message = sprintf("Unexpected '%s' in HTTP request response: %s", $this->userSession->message, $this->userSession->description);
} else {
$message = false;
}
throw new \RuntimeException($message ?: 'UserSession value expected, got ' . get_class($this->userSession), 0, isset($exceptionValue) ? $exceptionValue : null);
}
$this->resetDriver();
// apply session/csrf token to next request
$this->restDriver->setHeader('cookie', "{$this->userSession->sessionName}={$this->userSession->sessionId}");
$this->restDriver->setHeader('x-csrf-token', $this->userSession->csrfToken);
}