JWT
JWT
JWT Authentication Adapter.
This class provides a JWT authentication adapter for the Hazaar MVC framework.
- Full name:
\Hazaar\Auth\Storage\JWT
- This class implements:
\Hazaar\Auth\Interfaces\Storage
Properties
passphrase
protected ?string $passphrase
privateKey
protected ?string $privateKey
token
protected array $token
config
private \Hazaar\Map $config
data
private array<string,mixed> $data
writeCookie
private bool $writeCookie
clearCookie
private bool $clearCookie
Methods
__construct
Construct the storage.
public __construct(?\Hazaar\Map $config = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$config | ?\Hazaar\Map | The configuration |
isEmpty
Returns true if and only if storage is empty.
public isEmpty(): bool
read
Returns data from storage.
public read(): array<string,mixed>
write
Authorises the JWT token.
public write(array<string,mixed> $data): void
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array<string,mixed> |
has
Checks if a key exists in storage.
public has(string $key): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string |
get
Gets a value from storage.
public get(string $key): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string |
set
Sets a value in storage.
public set(string $key, mixed $value): void
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string | |
$value | mixed |
unset
Unsets a value in storage.
public unset(string $key): void
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string |
clear
Clears data from storage.
public clear(): void
getToken
Returns the storage session token.
public getToken(): array<string,string>
Return Value:
Storage token should be an array with at least a 'token' key and optionally a 'refresh' key
writeToken
public writeToken(): void
refresh
Refreshes the JWT token.
private refresh(string $refreshToken, array<string,mixed>& $JWTRefreshBody = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$refreshToken | string | |
$JWTRefreshBody | array<string,mixed> | the JWT body |
validateToken
Validates the JWT token.
private validateToken(string $token, array<string,mixed>& $JWTBody = null, string $passphrase = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$token | string | the JWT token |
$JWTBody | array<string,mixed> | the JWT body |
$passphrase | string | the passphrase |
checkToken
private checkToken(): bool
buildToken
Builds a JWT token with the given JWT body and passphrase.
private buildToken(array<string,mixed> $JWTBody, null|string $passphrase = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$JWTBody | array<string,mixed> | the body of the JWT token |
$passphrase | null|string | The passphrase to sign the JWT token. Defaults to null. |
Return Value:
the JWT token
buildRefreshTokenKey
private buildRefreshTokenKey(string $passphrase): string
Parameters:
Parameter | Type | Description |
---|---|---|
$passphrase | string |
sign
Signs the JWT token.
private sign(array<string,mixed> $JWTHeader, array<string,mixed> $JWTBody, ?string $passphrase = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$JWTHeader | array<string,mixed> | the header of the JWT token |
$JWTBody | array<string,mixed> | the body of the JWT token |
$passphrase | ?string |
Return Value:
the signature
Automatically generated on 2024-11-14