diff --git a/src/CTConfig.php b/src/CTConfig.php index 215e1e9..2326071 100644 --- a/src/CTConfig.php +++ b/src/CTConfig.php @@ -159,7 +159,7 @@ public static function getSessionCookie(): ?array if (empty($cookieData)) { return null; } - return end($cookieData); + return array_pop($cookieData); } public static function getSessionCookieString(): ?string diff --git a/src/Models/Common/Auth/AuthRequestBuilder.php b/src/Models/Common/Auth/AuthRequestBuilder.php index d91529e..00d02f9 100644 --- a/src/Models/Common/Auth/AuthRequestBuilder.php +++ b/src/Models/Common/Auth/AuthRequestBuilder.php @@ -7,6 +7,7 @@ use CTApi\Exceptions\CTRequestException; use CTApi\Models\Groups\Person\Person; use CTApi\Utils\CTResponseUtil; +use GuzzleHttp\Cookie\SetCookie; class AuthRequestBuilder { @@ -74,12 +75,13 @@ public function authWithLoginToken(string $loginToken): Auth public function authWithSessionCookie(string $cookieString): Auth { $client = CTClient::getClient(); + $cookie = SetCookie::fromString($cookieString); try { $response = $client->get('/api/whoami', [ 'headers' => [ - 'cookie' => $cookieString, - ] + 'cookie' => $cookie->getName() . '=' . $cookie->getValue(), + ], ]); $data = CTResponseUtil::dataAsArray($response); $person = Person::createModelFromData($data);