@@ -153,23 +153,29 @@ public static function decode(
153
153
// Check the nbf if it is defined. This is the time that the
154
154
// token can actually be used. If it's not yet that time, abort.
155
155
if (isset ($ payload ->nbf ) && floor ($ payload ->nbf ) > ($ timestamp + static ::$ leeway )) {
156
- throw new BeforeValidException (
156
+ $ ex = new BeforeValidException (
157
157
'Cannot handle token with nbf prior to ' . \date (DateTime::ISO8601 , (int ) $ payload ->nbf )
158
158
);
159
+ $ ex ->setPayload ($ payload );
160
+ throw $ ex ;
159
161
}
160
162
161
163
// Check that this token has been created before 'now'. This prevents
162
164
// using tokens that have been created for later use (and haven't
163
165
// correctly used the nbf claim).
164
166
if (!isset ($ payload ->nbf ) && isset ($ payload ->iat ) && floor ($ payload ->iat ) > ($ timestamp + static ::$ leeway )) {
165
- throw new BeforeValidException (
167
+ $ ex = new BeforeValidException (
166
168
'Cannot handle token with iat prior to ' . \date (DateTime::ISO8601 , (int ) $ payload ->iat )
167
169
);
170
+ $ ex ->setPayload ($ payload );
171
+ throw $ ex ;
168
172
}
169
173
170
174
// Check if this token has expired.
171
175
if (isset ($ payload ->exp ) && ($ timestamp - static ::$ leeway ) >= $ payload ->exp ) {
172
- throw new ExpiredException ('Expired token ' );
176
+ $ ex = new ExpiredException ('Expired token ' );
177
+ $ ex ->setPayload ($ payload );
178
+ throw $ ex ;
173
179
}
174
180
175
181
return $ payload ;
@@ -197,13 +203,14 @@ public static function encode(
197
203
string $ keyId = null ,
198
204
array $ head = null
199
205
): string {
200
- $ header = ['typ ' => 'JWT ' , 'alg ' => $ alg ];
206
+ $ header = ['typ ' => 'JWT ' ];
207
+ if (isset ($ head ) && \is_array ($ head )) {
208
+ $ header = \array_merge ($ header , $ head );
209
+ }
210
+ $ header ['alg ' ] = $ alg ;
201
211
if ($ keyId !== null ) {
202
212
$ header ['kid ' ] = $ keyId ;
203
213
}
204
- if (isset ($ head ) && \is_array ($ head )) {
205
- $ header = \array_merge ($ head , $ header );
206
- }
207
214
$ segments = [];
208
215
$ segments [] = static ::urlsafeB64Encode ((string ) static ::jsonEncode ($ header ));
209
216
$ segments [] = static ::urlsafeB64Encode ((string ) static ::jsonEncode ($ payload ));
0 commit comments