Revert "fix: enforce configured session timeout"

This reverts commit 75d6e45080.
This commit is contained in:
OpenClaw Agent
2026-09-21 20:00:27 +08:00
parent 725c3a08b1
commit 20e77e47c9
2 changed files with 3 additions and 14 deletions
+2 -6
View File
@@ -339,16 +339,12 @@ func (s *Server) session(w http.ResponseWriter, r *http.Request) {
writeJSONError(w, http.StatusNotFound, "user or password is wrong") writeJSONError(w, http.StatusNotFound, "user or password is wrong")
return return
} }
ttl := 365 * 24 * time.Hour token, err := auth.NewToken(a.Username)
if s.SessionTimeout > 0 {
ttl = time.Duration(s.SessionTimeout) * time.Minute
}
token, err := auth.NewTokenWithTTL(a.Username, ttl)
if err != nil { if err != nil {
writeJSONError(w, http.StatusInternalServerError, "failed to create token") writeJSONError(w, http.StatusInternalServerError, "failed to create token")
return return
} }
expires := time.Now().Add(ttl) expires := time.Now().Add(365 * 24 * time.Hour)
http.SetCookie(w, &http.Cookie{Name: "JWT", Value: token, Path: "/", Expires: expires, HttpOnly: true}) http.SetCookie(w, &http.Cookie{Name: "JWT", Value: token, Path: "/", Expires: expires, HttpOnly: true})
http.SetCookie(w, &http.Cookie{Name: "user", Value: a.Username, Path: "/", Expires: expires}) http.SetCookie(w, &http.Cookie{Name: "user", Value: a.Username, Path: "/", Expires: expires})
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
+1 -8
View File
@@ -187,14 +187,7 @@ type jwtClaims struct {
} }
func NewToken(username string) (string, error) { func NewToken(username string) (string, error) {
return NewTokenWithTTL(username, 365*24*time.Hour) claims := jwtClaims{Acc: username, StandardClaims: jwt.StandardClaims{ExpiresAt: time.Now().Add(365 * 24 * time.Hour).Unix()}}
}
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) token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString([]byte(jwtSecret)) return token.SignedString([]byte(jwtSecret))
} }