Auto login using X-Auth-Request-User header

This commit is contained in:
Maximilian Friedersdorff 2025-09-30 09:57:10 +01:00
parent 3c60b6265e
commit c098abf14f

View file

@ -58,16 +58,26 @@ func (s *SessionStore) AsMiddleware(next http.Handler) http.Handler {
// No session yet // No session yet
if err != nil { if err != nil {
http.Redirect(w, r, "/login/", http.StatusFound) user := r.Header.Get("X-Auth-Request-User")
return if user != "" {
s.Login(user, w)
} else {
http.Redirect(w, r, "/login/", http.StatusFound)
return
}
} }
session, ok := s.sessions[sessionCookie.Value] session, ok := s.sessions[sessionCookie.Value]
// Session expired // Session expired
if !ok { if !ok {
http.Redirect(w, r, "/login/", http.StatusFound) user := r.Header.Get("X-Auth-Request-User")
return if user != "" {
s.Login(user, w)
} else {
http.Redirect(w, r, "/login/", http.StatusFound)
return
}
} }
ctx := r.Context() ctx := r.Context()