1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 06:28:42 +01:00

feat: supports auth ttl to override session with DOZZLE_AUTH_TTL env. (#3313)

This commit is contained in:
Amir Raminfar
2024-10-06 06:31:40 -07:00
committed by GitHub
parent 423e4e11a3
commit 567337649e
7 changed files with 71 additions and 6 deletions

View File

@@ -12,12 +12,18 @@ func (h *handler) createToken(w http.ResponseWriter, r *http.Request) {
pass := r.PostFormValue("password")
if token, err := h.config.Authorization.Authorizer.CreateToken(user, pass); err == nil {
expires := time.Time{}
if h.config.Authorization.TTL > 0 {
expires = time.Now().Add(h.config.Authorization.TTL)
}
http.SetCookie(w, &http.Cookie{
Name: "jwt",
Value: token,
HttpOnly: true,
Path: "/",
SameSite: http.SameSiteLaxMode,
Expires: expires,
})
log.Info().Str("user", user).Msg("Token created")
w.WriteHeader(http.StatusOK)