Cookie
Cookie
Cookie-based auth token transport implementation.
class Cookie implements \Hazaar\Auth\Interface\SessionTransportImplements: Hazaar\Auth\Interface\SessionTransport
Implements Hazaar\Auth\Interface\SessionTransport by reading auth tokens from incoming request cookies and writing/removing token cookies on outgoing responses through Set-Cookie headers.
The transport supports configurable cookie attributes, including path, domain, secure, HttpOnly, SameSite, and expiration, with per-call option overrides for persist/clear operations.
Properties
options
private array $optionsType: array
Methods
__construct
CookieTransport constructor.
public __construct(array|Options $cookieOptions): voidParameters
| Parameter | Type | Description |
|---|---|---|
$cookieOptions | array | Hazaar\Auth\Session\Transport\Cookie\Options |
extractToken
Extracts the authentication token from the cookie.
public extractToken(array $options): ?stringReturns: string
Retrieves the value of the cookie specified by $this->cookieName from the $_COOKIE superglobal. Returns the token as a string if the cookie exists, or null if it does not.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array |
extractRefreshToken
public extractRefreshToken(array $options): ?stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array |
persistToken
Persists the authentication token in a cookie with the specified options.
public persistToken(Response $response, ExpiringToken $token, array $options): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Hazaar\Controller\Response | |
$token | Hazaar\Auth\ExpiringToken | the authentication token to be stored in the cookie |
$options | array |
persistRefreshToken
Persists the refresh token in a separate cookie.
public persistRefreshToken(Response $response, ExpiringToken $refreshToken, array $options): voidReturns: void
Stores the provided refresh token in a cookie named "{$this->cookieName}-refresh" using the given response object. Cookie options such as path, domain, secure, httponly, samesite, and expires can be customized via the $options parameter.
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Hazaar\Controller\Response | the response object to which the Set-Cookie header will be added |
$refreshToken | Hazaar\Auth\ExpiringToken | the refresh token to be stored in the cookie |
$options | array | optional cookie settings to override default options |
clearToken
Clears the authentication token by removing the corresponding cookie.
public clearToken(Response $response, array $options): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Hazaar\Controller\Response | |
$options | array |
persistenceMode
Returns Hazaar\Auth\Enum\TransportPersistence::ServerManaged because cookies are
public persistenceMode(): TransportPersistenceReturns: Hazaar\Auth\Enum\TransportPersistence
written via Set-Cookie and replayed by the browser automatically.
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000