Claim and Header Validation
After verifying a signature or decrypting a token, you must validate the claims and headers before trusting the token content.
Never use a token payload without validating its claims. An expired or wrongly-issued token must be rejected.
Validate Claims
The ClaimCheckerManager verifies claims contained in the token payload.
<?php
use Jose\Component\Checker\AudienceChecker;
use Jose\Component\Checker\ClaimCheckerManager;
use Jose\Component\Checker\ExpirationTimeChecker;
use Jose\Component\Checker\IssuedAtChecker;
use Jose\Component\Checker\IssuerChecker;
use Jose\Component\Checker\NotBeforeChecker;
use Symfony\Component\Clock\NativeClock;
require_once 'vendor/autoload.php';
// A PSR-20 clock implementation is required for time-based checkers
$clock = new NativeClock();
$claimCheckerManager = new ClaimCheckerManager([
new IssuedAtChecker($clock),
new NotBeforeChecker($clock),
new ExpirationTimeChecker($clock),
new IssuerChecker(['https://auth.example.com']),
new AudienceChecker('https://api.example.com'),
]);
// $payload is the decoded payload from a verified JWS or decrypted JWE
$payload = json_decode($jws->getPayload(), true);
// Check claims. The second parameter lists the mandatory claims.
$claimCheckerManager->check($payload, ['iss', 'aud', 'exp']);
// Throws an exception if any check failsAllow a Time Drift
Network latency or clock skew between servers may cause valid tokens to be rejected. You can allow a small time drift (in seconds):
Custom Claim Validation with CallableChecker
For application-specific claims, use the CallableChecker:
Validate with IsEqualChecker
For simple equality checks on claims or headers:
Complete Example: Sign, Verify, and Validate
A full example combining token creation, verification, and claim validation:
Last updated
Was this helpful?