Skip to content

Commit

Permalink
minor: Future
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Sep 8, 2023
1 parent a0541d7 commit 454d951
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion leeway.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jwt

import "time"
import (
"errors"
"time"
)

// Leeway adds validation for a leeway expiration time.
// If the token was not expired then a comparison between
Expand All @@ -18,3 +21,22 @@ func Leeway(leeway time.Duration) TokenValidatorFunc {
return err
}
}

// Future adds a validation for the "iat" claim.
// It checks if the token was issued in the future based on now+dur < iat.
//
// Example of use case: allow tokens that are going to be issued in the future,
// for example a token that is going to be issued in 10 seconds from now.
func Future(dur time.Duration) TokenValidatorFunc {
return func(_ []byte, standardClaims Claims, err error) error {
if errors.Is(err, ErrIssuedInTheFuture) {
if Clock().Add(dur).Round(time.Second).Unix() < standardClaims.IssuedAt {
return ErrIssuedInTheFuture
}

return nil
}

return err
}
}

0 comments on commit 454d951

Please sign in to comment.