From 896d5e61988a9afc967e0ac4177fd184e5571c3f Mon Sep 17 00:00:00 2001 From: James Miller Date: Mon, 30 Sep 2024 17:34:12 -0700 Subject: [PATCH] fix confusion with passing duration for exp instead of seconds --- cmd/jwt_issuer_parameter_store/main_test.go | 2 +- internal/issuer/jwt.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/jwt_issuer_parameter_store/main_test.go b/cmd/jwt_issuer_parameter_store/main_test.go index eaf4c4b..18a6ceb 100644 --- a/cmd/jwt_issuer_parameter_store/main_test.go +++ b/cmd/jwt_issuer_parameter_store/main_test.go @@ -33,7 +33,7 @@ func Test_handler(t *testing.T) { publicKeyObj, err := jwt.ParseECPublicKeyFromPEM(publicKeyPEM) require.NoError(t, err) - output, err := handler(context.Background(), issuer.JWTIssuerFunctionInput{Claims: claims, TTL: lo.ToPtr(time.Duration(60)), SetIat: lo.ToPtr(true), SetJti: lo.ToPtr(true)}) + output, err := handler(context.Background(), issuer.JWTIssuerFunctionInput{Claims: claims, TTL: lo.ToPtr(int64(60)), SetIat: lo.ToPtr(true), SetJti: lo.ToPtr(true)}) require.NoError(t, err) generatedToken, err := jwt.Parse(output.Token, func(t *jwt.Token) (any, error) { diff --git a/internal/issuer/jwt.go b/internal/issuer/jwt.go index 41af065..2b19fd9 100644 --- a/internal/issuer/jwt.go +++ b/internal/issuer/jwt.go @@ -20,7 +20,7 @@ type JWTIssuerFunctionInput struct { // Optional number of seconds until the token will expire. Overrides "exp" in // Claims, if provided. - TTL *time.Duration `json:"ttl,omitempty"` + TTL *int64 `json:"ttl,omitempty"` // All the claims for the token. Claims jwt.MapClaims `json:"claims,omitempty"` @@ -42,7 +42,7 @@ func PrepareToken(input JWTIssuerFunctionInput, keyID string) *jwt.Token { } if input.TTL != nil { - input.Claims["exp"] = jwt.NewNumericDate(now.Add(time.Second * lo.FromPtr(input.TTL))) + input.Claims["exp"] = jwt.NewNumericDate(now.Add(time.Second * time.Duration(lo.FromPtr(input.TTL)))) } if lo.FromPtr(input.SetJti) {