1717 * This class is a claim checker.
1818 * When the "iat" is present, it will compare the value with the current timestamp.
1919 */
20- final class IssuedAtChecker implements ClaimChecker
20+ final class IssuedAtChecker implements ClaimChecker, HeaderChecker
2121{
22- private const CLAIM_NAME = 'iat ' ;
22+ private const NAME = 'iat ' ;
2323
2424 /**
2525 * @var int
2626 */
2727 private $ allowedTimeDrift ;
28+ /**
29+ * @var bool
30+ */
31+ private $ protectedHeaderOnly ;
2832
29- public function __construct (int $ allowedTimeDrift = 0 )
33+ public function __construct (int $ allowedTimeDrift = 0 , bool $ protectedHeaderOnly = false )
3034 {
3135 $ this ->allowedTimeDrift = $ allowedTimeDrift ;
36+ $ this ->protectedHeaderOnly = $ protectedHeaderOnly ;
3237 }
3338
3439 /**
@@ -37,15 +42,35 @@ public function __construct(int $allowedTimeDrift = 0)
3742 public function checkClaim ($ value ): void
3843 {
3944 if (!\is_int ($ value )) {
40- throw new InvalidClaimException ('The claim "iat" must be an integer. ' , self ::CLAIM_NAME , $ value );
45+ throw new InvalidClaimException ('"iat" must be an integer. ' , self ::NAME , $ value );
4146 }
4247 if (time () < $ value - $ this ->allowedTimeDrift ) {
43- throw new InvalidClaimException ('The JWT is issued in the future. ' , self ::CLAIM_NAME , $ value );
48+ throw new InvalidClaimException ('The JWT is issued in the future. ' , self ::NAME , $ value );
4449 }
4550 }
4651
4752 public function supportedClaim (): string
4853 {
49- return self ::CLAIM_NAME ;
54+ return self ::NAME ;
55+ }
56+
57+ public function checkHeader ($ value ): void
58+ {
59+ if (!\is_int ($ value )) {
60+ throw new InvalidHeaderException ('The header "iat" must be an integer. ' , self ::NAME , $ value );
61+ }
62+ if (time () < $ value - $ this ->allowedTimeDrift ) {
63+ throw new InvalidHeaderException ('The JWT is issued in the future. ' , self ::NAME , $ value );
64+ }
65+ }
66+
67+ public function supportedHeader (): string
68+ {
69+ return self ::NAME ;
70+ }
71+
72+ public function protectedHeaderOnly (): bool
73+ {
74+ return $ this ->protectedHeaderOnly ;
5075 }
5176}
0 commit comments