fix: enforce configured session timeout
This commit is contained in:
@@ -187,7 +187,14 @@ type jwtClaims struct {
|
||||
}
|
||||
|
||||
func NewToken(username string) (string, error) {
|
||||
claims := jwtClaims{Acc: username, StandardClaims: jwt.StandardClaims{ExpiresAt: time.Now().Add(365 * 24 * time.Hour).Unix()}}
|
||||
return NewTokenWithTTL(username, 365*24*time.Hour)
|
||||
}
|
||||
|
||||
func NewTokenWithTTL(username string, ttl time.Duration) (string, error) {
|
||||
if ttl <= 0 {
|
||||
return "", fmt.Errorf("invalid token ttl")
|
||||
}
|
||||
claims := jwtClaims{Acc: username, StandardClaims: jwt.StandardClaims{ExpiresAt: time.Now().Add(ttl).Unix()}}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString([]byte(jwtSecret))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user