Claim and Header Validation
Validate Claims
<?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
Custom Claim Validation with CallableChecker
Validate with IsEqualChecker
Complete Example: Sign, Verify, and Validate
Last updated
Was this helpful?