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