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
6
6
{
7
7
private object $ payload ;
8
8
9
+ private ?int $ timestamp = null ;
10
+
9
11
public function setPayload (object $ payload ): void
10
12
{
11
13
$ this ->payload = $ payload ;
@@ -15,4 +17,14 @@ public function getPayload(): object
15
17
{
16
18
return $ this ->payload ;
17
19
}
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
+ }
18
30
}
Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ public static function decode(
185
185
if (isset ($ payload ->exp ) && ($ timestamp - static ::$ leeway ) >= $ payload ->exp ) {
186
186
$ ex = new ExpiredException ('Expired token ' );
187
187
$ ex ->setPayload ($ payload );
188
+ $ ex ->setTimestamp ($ timestamp );
188
189
throw $ ex ;
189
190
}
190
191
Original file line number Diff line number Diff line change @@ -130,6 +130,29 @@ public function testExpiredExceptionPayload()
130
130
}
131
131
}
132
132
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
+
133
156
public function testBeforeValidExceptionPayload ()
134
157
{
135
158
$ this ->expectException (BeforeValidException::class);
You can’t perform that action at this time.
0 commit comments