CookieStore
in package
implements
StoreInterface
This class provides a layer to persist transient auth data using cookies.
Table of Contents
Interfaces
Constants
- KEY_CHUNKING_THRESHOLD : int = 2048
- KEY_HASHING_ALGO : string = 'sha256'
- KEY_SEPARATOR : string = '_'
- VAL_CRYPTO_ALGO : string = 'aes-128-gcm'
- VAL_CRYPTO_ALGO_V2 : string = 'aes-256-gcm'
- VAL_CRYPTO_KEY_LENGTH : int = 32
- VAL_CRYPTO_TAG_LENGTH_BYTES : int = 16
- VAL_CRYPTO_VERSION : int = 2
- KEY_DERIVATION_ALGO : string = 'sha256'
- KEY_DERIVATION_INFO : string = 'auth0-php-cookie-encryption'
Properties
- $configuration : SdkConfiguration
- $deferring : bool
- When true, CookieStore will not setState() itself. You will need manually call the method to persist state to storage.
- $dirty : bool
- Determine if changes have been made since the last setState.
- $encrypt : bool
- Determine if changes have been made since the last setState.
- $namespace : string
- $store : array<string|int, mixed>
- Internal cache of the storage state.
Methods
- __construct() : mixed
- CookieStore constructor.
- decrypt() : null|array<string|int, mixed>
- Decrypt data from a stored cookie string.
- defer() : void
- Defer saving state changes to destination to improve performance during blocks of changes.
- delete() : void
- Removes a persisted value identified by $key.
- encrypt() : string
- Encrypt data for safe storage format for a cookie.
- get() : mixed
- Gets persisted values identified by $key.
- getCookieOptions() : array{expires: int, path: string, domain?: string, secure: bool, httponly: bool, samesite: string, url_encode?: int}
- Build options array for use with setcookie().
- getEncrypted() : bool
- Returns the current encryption state.
- getNamespace() : string
- Returns the current namespace identifier.
- getState() : array<string|int, mixed>
- Setup our storage state by pulling from persistence source.
- purge() : void
- Removes all persisted values.
- set() : void
- Persists $value on cookies, identified by $key.
- setEncrypted() : self
- Toggle the encryption state.
- setState() : self
- Push our storage state to the source for persistence.
- deriveKey() : string
- Derive an encryption key from the cookie secret using HKDF.
Constants
KEY_CHUNKING_THRESHOLD
public
int
KEY_CHUNKING_THRESHOLD
= 2048
KEY_HASHING_ALGO
public
string
KEY_HASHING_ALGO
= 'sha256'
KEY_SEPARATOR
public
string
KEY_SEPARATOR
= '_'
VAL_CRYPTO_ALGO
public
string
VAL_CRYPTO_ALGO
= 'aes-128-gcm'
VAL_CRYPTO_ALGO_V2
public
string
VAL_CRYPTO_ALGO_V2
= 'aes-256-gcm'
VAL_CRYPTO_KEY_LENGTH
public
int
VAL_CRYPTO_KEY_LENGTH
= 32
VAL_CRYPTO_TAG_LENGTH_BYTES
public
int
VAL_CRYPTO_TAG_LENGTH_BYTES
= 16
VAL_CRYPTO_VERSION
public
int
VAL_CRYPTO_VERSION
= 2
KEY_DERIVATION_ALGO
private
string
KEY_DERIVATION_ALGO
= 'sha256'
KEY_DERIVATION_INFO
private
string
KEY_DERIVATION_INFO
= 'auth0-php-cookie-encryption'
Properties
$configuration read-only
private
SdkConfiguration
$configuration
$deferring
When true, CookieStore will not setState() itself. You will need manually call the method to persist state to storage.
private
bool
$deferring
= false
$dirty
Determine if changes have been made since the last setState.
private
bool
$dirty
= false
$encrypt
Determine if changes have been made since the last setState.
private
bool
$encrypt
= true
$namespace read-only
private
string
$namespace
= 'auth0'
$store
Internal cache of the storage state.
private
array<string|int, mixed>
$store
Methods
__construct()
CookieStore constructor.
public
__construct(SdkConfiguration $configuration[, string $namespace = 'auth0' ]) : mixed
Parameters
- $configuration : SdkConfiguration
-
Base configuration options for the SDK. See the SdkConfiguration class constructor for options.
- $namespace : string = 'auth0'
-
a string in which to store cookies under on devices
Tags
decrypt()
Decrypt data from a stored cookie string.
public
decrypt(string $data) : null|array<string|int, mixed>
Parameters
- $data : string
-
string representing an encrypted data structure
Tags
Return values
null|array<string|int, mixed>defer()
Defer saving state changes to destination to improve performance during blocks of changes.
public
defer(bool $deferring) : void
Parameters
- $deferring : bool
-
whether to defer persisting the storage state
delete()
Removes a persisted value identified by $key.
public
delete(string $key) : void
Parameters
- $key : string
-
cookie to delete
encrypt()
Encrypt data for safe storage format for a cookie.
public
encrypt(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $data : array<string|int, mixed>
-
data to encrypt
- $options : array<string|int, mixed> = []
-
additional configuration options
Tags
Return values
stringget()
Gets persisted values identified by $key.
public
get(string $key[, mixed $default = null ]) : mixed
If the value is not set, returns $default.
Parameters
- $key : string
-
cookie to set
- $default : mixed = null
-
default to return if nothing was found
getCookieOptions()
Build options array for use with setcookie().
public
getCookieOptions([int|null $expires = null ]) : array{expires: int, path: string, domain?: string, secure: bool, httponly: bool, samesite: string, url_encode?: int}
Parameters
- $expires : int|null = null
Return values
array{expires: int, path: string, domain?: string, secure: bool, httponly: bool, samesite: string, url_encode?: int}getEncrypted()
Returns the current encryption state.
public
getEncrypted() : bool
Return values
boolgetNamespace()
Returns the current namespace identifier.
public
getNamespace() : string
Return values
stringgetState()
Setup our storage state by pulling from persistence source.
public
getState([null|array<string|int, mixed> $state = null ]) : array<string|int, mixed>
Parameters
- $state : null|array<string|int, mixed> = null
-
skip loading any persistent source state and inject a custom state
Return values
array<string|int, mixed>purge()
Removes all persisted values.
public
purge() : void
set()
Persists $value on cookies, identified by $key.
public
set(string $key, mixed $value) : void
Parameters
- $key : string
-
cookie to set
- $value : mixed
-
value to use
setEncrypted()
Toggle the encryption state.
public
setEncrypted([bool $encrypt = true ]) : self
Parameters
- $encrypt : bool = true
-
enable or disable cookie encryption
Return values
selfsetState()
Push our storage state to the source for persistence.
public
setState([bool $force = false ]) : self
Parameters
- $force : bool = false
Tags
Return values
selfderiveKey()
Derive an encryption key from the cookie secret using HKDF.
private
deriveKey(string $secret) : string
Parameters
- $secret : string
-
the raw cookie secret
Return values
string —the derived key bytes