File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ class ExpiredException extends \UnexpectedValueException implements JWTException
66{
77 private object $ payload ;
88
9+ private ?int $ timestamp = null ;
10+
911 public function setPayload (object $ payload ): void
1012 {
1113 $ this ->payload = $ payload ;
@@ -15,4 +17,14 @@ public function getPayload(): object
1517 {
1618 return $ this ->payload ;
1719 }
20+
21+ public function setTimestamp (int $ timestamp ): void
22+ {
23+ $ this ->timestamp = $ timestamp ;
24+ }
25+
26+ public function getTimestamp (): ?int
27+ {
28+ return $ this ->timestamp ;
29+ }
1830}
Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ public static function decode(
185185 if (isset ($ payload ->exp ) && ($ timestamp - static ::$ leeway ) >= $ payload ->exp ) {
186186 $ ex = new ExpiredException ('Expired token ' );
187187 $ ex ->setPayload ($ payload );
188+ $ ex ->setTimestamp ($ timestamp );
188189 throw $ ex ;
189190 }
190191
Original file line number Diff line number Diff line change @@ -130,6 +130,29 @@ public function testExpiredExceptionPayload()
130130 }
131131 }
132132
133+ /**
134+ * @runInSeparateProcess
135+ */
136+ public function testExpiredExceptionTimestamp ()
137+ {
138+ $ this ->expectException (ExpiredException::class);
139+
140+ JWT ::$ timestamp = 98765 ;
141+ $ payload = [
142+ 'message ' => 'abc ' ,
143+ 'exp ' => 1234 ,
144+ ];
145+ $ encoded = JWT ::encode ($ payload , 'my_key ' , 'HS256 ' );
146+
147+ try {
148+ JWT ::decode ($ encoded , new Key ('my_key ' , 'HS256 ' ));
149+ } catch (ExpiredException $ e ) {
150+ $ exTimestamp = $ e ->getTimestamp ();
151+ $ this ->assertSame (98765 , $ exTimestamp );
152+ throw $ e ;
153+ }
154+ }
155+
133156 public function testBeforeValidExceptionPayload ()
134157 {
135158 $ this ->expectException (BeforeValidException::class);
You can’t perform that action at this time.
0 commit comments