From 56d559fdd712fc04d2b4f3cda7ffd2b08d6d3a18 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 18 Aug 2023 09:19:30 +0200 Subject: [PATCH] Fix bug with jwt max-age option --- internal/auth/jwt.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/auth/jwt.go b/internal/auth/jwt.go index 9c0166d..3d87f68 100644 --- a/internal/auth/jwt.go +++ b/internal/auth/jwt.go @@ -130,8 +130,12 @@ func (ja *JWTAuthenticator) ProvideJWT(user *schema.User) (string, error) { "roles": user.Roles, "iat": now.Unix(), } - if ja.config != nil && ja.config.MaxAge != 0 { - claims["exp"] = now.Add(time.Duration(ja.config.MaxAge)).Unix() + if ja.config != nil && ja.config.MaxAge != "" { + d, err := time.ParseDuration(ja.config.MaxAge) + if err != nil { + return "", errors.New("cannot parse max-age config key") + } + claims["exp"] = now.Add(d).Unix() } return jwt.NewWithClaims(jwt.SigningMethodEdDSA, claims).SignedString(ja.privateKey)