Auto login using X-Auth-Request-User header
This commit is contained in:
parent
3c60b6265e
commit
c098abf14f
1 changed files with 14 additions and 4 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue