File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
package jwt
2
2
3
- import "time"
3
+ import (
4
+ "errors"
5
+ "time"
6
+ )
4
7
5
8
// Leeway adds validation for a leeway expiration time.
6
9
// If the token was not expired then a comparison between
@@ -18,3 +21,22 @@ func Leeway(leeway time.Duration) TokenValidatorFunc {
18
21
return err
19
22
}
20
23
}
24
+
25
+ // Future adds a validation for the "iat" claim.
26
+ // It checks if the token was issued in the future based on now+dur < iat.
27
+ //
28
+ // Example of use case: allow tokens that are going to be issued in the future,
29
+ // for example a token that is going to be issued in 10 seconds from now.
30
+ func Future (dur time.Duration ) TokenValidatorFunc {
31
+ return func (_ []byte , standardClaims Claims , err error ) error {
32
+ if errors .Is (err , ErrIssuedInTheFuture ) {
33
+ if Clock ().Add (dur ).Round (time .Second ).Unix () < standardClaims .IssuedAt {
34
+ return ErrIssuedInTheFuture
35
+ }
36
+
37
+ return nil
38
+ }
39
+
40
+ return err
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments