Skip to content

Commit

Permalink
fix confusion with passing duration for exp instead of seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
bensie committed Oct 1, 2024
1 parent c573022 commit 896d5e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/jwt_issuer_parameter_store/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions internal/issuer/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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) {
Expand Down

0 comments on commit 896d5e6

Please sign in to comment.