Skip to content

Commit

Permalink
Make session cookie auth more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
devdot committed Jul 30, 2024
1 parent 34e90d5 commit 6a4baa8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CTConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Models/Common/Auth/AuthRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use CTApi\Exceptions\CTRequestException;
use CTApi\Models\Groups\Person\Person;
use CTApi\Utils\CTResponseUtil;
use GuzzleHttp\Cookie\SetCookie;

class AuthRequestBuilder
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a4baa8

Please sign in to comment.