Skip to content

JwtTokenValidator

Verifies a JWS via firebase/php-jwt (JWKS + rotation via CachedKeySet for RS256/ES256, or a single Key for a shared HS256 secret) and enforces iss/aud — the library itself only checks exp/nbf/iat.

Callers are responsible for binding $key to RS256/ES256 only (never mixing in a symmetric key), which is a property of how $key is constructed, not this class.

final class JwtTokenValidator implements TokenValidatorInterface

ImplementsTokenValidatorInterface
Since1.0.0
SourceJwtTokenValidator.php

public function __construct(Key|array<string, Key>|CachedKeySet $key, string $issuer, string $audience, int $leeway = 60): mixed

Clock-skew allowance in seconds applied to exp/nbf/iat (~60 is a reasonable default).

ParameterTypeDescription
$key`Key“array<string, Key>“
$issuerstringThe expected iss claim (the token authority).
$audiencestringThe expected aud claim (this resource’s identifier).
$leewayintClock-skew allowance in seconds applied to exp/nbf/iat (~60 is a reasonable default).

Returns mixed

MethodDescription
validate(string $token): array<string, mixed>

public function validate(string $token): array<string, mixed>

The raw, encoded token (e.g. the value after Bearer ).

ParameterTypeDescription
$tokenstringThe raw, encoded token (e.g. the value after Bearer ).

Returns array``<``string``, ``mixed``> — The validated, raw claim set.

ThrowsWhen
AuthenticationExceptionIf the token is malformed, expired, or fails signature/iss/aud checks.