@@ -25,11 +25,11 @@ void main() {
2525 });
2626
2727 test ('should be still valid' , () {
28- final iat = DateTime (2023 );
29- final exp = DateTime (2023 ).add (Duration (hours: 1 ));
28+ final iat = DateTime (2042 );
29+ final exp = DateTime (2042 ).add (Duration (hours: 1 ));
3030
3131 withClock (
32- Clock .fixed (DateTime (2023 )),
32+ Clock .fixed (DateTime (2042 )),
3333 () {
3434 final duration = Duration (hours: 1 );
3535 final token = JWT ({'foo' : 'bar' }).sign (hsKey, expiresIn: duration);
@@ -61,7 +61,7 @@ void main() {
6161 });
6262
6363 //----------------------//
64- // Not Before (nbf) //
64+ // Not Before (nbf) //
6565 //----------------------//
6666 group ('nbf' , () {
6767 test ('should throw when token is not yet valid' , () {
@@ -75,11 +75,11 @@ void main() {
7575 });
7676
7777 test ('should be valid after nbf time' , () {
78- final iat = DateTime (2023 );
78+ final iat = DateTime (2042 );
7979 final nbf = iat.add (Duration (minutes: 30 ));
8080
8181 withClock (
82- Clock .fixed (DateTime (2023 )),
82+ Clock .fixed (DateTime (2042 )),
8383 () {
8484 final token = JWT ({'foo' : 'bar' }).sign (
8585 hsKey,
@@ -112,6 +112,40 @@ void main() {
112112 contains ('foo' ),
113113 );
114114 });
115+
116+ //----------------------//
117+ // Issued At (iat) //
118+ //----------------------//
119+ group ('iat' , () {
120+ test ('should have iat claim by default' , () {
121+ final iat = DateTime (2042 );
122+
123+ withClock (Clock .fixed (iat), () {
124+ final token = JWT ({'foo' : 'bar' }).sign (hsKey);
125+
126+ expect (
127+ JWT .verify (token, hsKey).payload,
128+ equals ({
129+ 'foo' : 'bar' ,
130+ 'iat' : iat.millisecondsSinceEpoch ~ / 1000 ,
131+ }),
132+ );
133+ });
134+ });
135+
136+ test ('should be valid when iat is in the future' , () {
137+ final futureIat = DateTime (2042 ).add (Duration (hours: 1 ));
138+ final token = JWT ({
139+ 'foo' : 'bar' ,
140+ 'iat' : futureIat.millisecondsSinceEpoch ~ / 1000
141+ }).sign (hsKey);
142+
143+ expect (
144+ JWT .verify (token, hsKey).payload,
145+ contains ('foo' ),
146+ );
147+ });
148+ });
115149 });
116150 });
117151}
0 commit comments