fix(jwt): generate JWT IDs BE-11179 (#12176)

pull/12178/head
andres-portainer 3 months ago committed by GitHub
parent 6cc95e11ae
commit 273ea5df23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -7,9 +7,10 @@ import (
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices" "github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/internal/securecookie"
"github.com/gofrs/uuid"
"github.com/golang-jwt/jwt/v4" "github.com/golang-jwt/jwt/v4"
"github.com/portainer/portainer/api/internal/securecookie"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@ -174,6 +175,11 @@ func (service *Service) generateSignedToken(data *portainer.TokenData, expiresAt
expiresAt = time.Now().Add(time.Hour * 8760 * 99).Unix() expiresAt = time.Now().Add(time.Hour * 8760 * 99).Unix()
} }
uuid, err := uuid.NewV4()
if err != nil {
return "", fmt.Errorf("unable to generate the JWT ID: %w", err)
}
cl := claims{ cl := claims{
UserID: int(data.ID), UserID: int(data.ID),
Username: data.Username, Username: data.Username,
@ -181,6 +187,7 @@ func (service *Service) generateSignedToken(data *portainer.TokenData, expiresAt
Scope: scope, Scope: scope,
ForceChangePassword: data.ForceChangePassword, ForceChangePassword: data.ForceChangePassword,
StandardClaims: jwt.StandardClaims{ StandardClaims: jwt.StandardClaims{
Id: uuid.String(),
ExpiresAt: expiresAt, ExpiresAt: expiresAt,
IssuedAt: time.Now().Unix(), IssuedAt: time.Now().Unix(),
}, },

Loading…
Cancel
Save