Fix auth user on non auth paths
This commit is contained in:
parent
f583b02d88
commit
767811eec6
1
go.sum
1
go.sum
|
@ -10,6 +10,7 @@ github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -67,9 +67,14 @@ func (s *Server) authenticated(auth auth.Authenticator, redirect string, handle
|
|||
func (s *Server) wrapper(handle func(c *Context)) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("request: ", r.RequestURI)
|
||||
c := s.makeContext(nil, w, r)
|
||||
handle(c)
|
||||
|
||||
c := s.makeContext(nil, w, r)
|
||||
if s.auth != nil {
|
||||
if rec, ok := s.auth.DoAuth(w, r); ok {
|
||||
c.auth = rec
|
||||
}
|
||||
}
|
||||
handle(c)
|
||||
// discard the rest of the body content
|
||||
io.Copy(ioutil.Discard, r.Body)
|
||||
defer r.Body.Close()
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestServer_BasicAuth(t *testing.T) {
|
|||
s.WithTheme("skin/")
|
||||
s.HandleFunc("/", handlerRoot)
|
||||
s.HandleFuncAuthenticated("/login", "", handlerLogin)
|
||||
s.HandleFuncAuthenticated("/test", "", handlerTest)
|
||||
s.HandleFunc("/test", handlerTest)
|
||||
s.Dump()
|
||||
|
||||
ts := httptest.NewServer(s.router)
|
||||
|
|
Loading…
Reference in New Issue