|
|
@ -24,6 +24,8 @@ import ( |
|
|
|
"github.com/golang-jwt/jwt/v4" |
|
|
|
"github.com/golang-jwt/jwt/v4" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const jwtExpiryTimeout = 60 * time.Second |
|
|
|
|
|
|
|
|
|
|
|
type jwtHandler struct { |
|
|
|
type jwtHandler struct { |
|
|
|
keyFunc func(token *jwt.Token) (interface{}, error) |
|
|
|
keyFunc func(token *jwt.Token) (interface{}, error) |
|
|
|
next http.Handler |
|
|
|
next http.Handler |
|
|
@ -68,9 +70,9 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) { |
|
|
|
http.Error(out, "token is expired", http.StatusForbidden) |
|
|
|
http.Error(out, "token is expired", http.StatusForbidden) |
|
|
|
case claims.IssuedAt == nil: |
|
|
|
case claims.IssuedAt == nil: |
|
|
|
http.Error(out, "missing issued-at", http.StatusForbidden) |
|
|
|
http.Error(out, "missing issued-at", http.StatusForbidden) |
|
|
|
case time.Since(claims.IssuedAt.Time) > 5*time.Second: |
|
|
|
case time.Since(claims.IssuedAt.Time) > jwtExpiryTimeout: |
|
|
|
http.Error(out, "stale token", http.StatusForbidden) |
|
|
|
http.Error(out, "stale token", http.StatusForbidden) |
|
|
|
case time.Until(claims.IssuedAt.Time) > 5*time.Second: |
|
|
|
case time.Until(claims.IssuedAt.Time) > jwtExpiryTimeout: |
|
|
|
http.Error(out, "future token", http.StatusForbidden) |
|
|
|
http.Error(out, "future token", http.StatusForbidden) |
|
|
|
default: |
|
|
|
default: |
|
|
|
handler.next.ServeHTTP(out, r) |
|
|
|
handler.next.ServeHTTP(out, r) |
|
|
|