From e65ade4f38f78733f310384b76ef9e1d451b6c53 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Mon, 15 Jan 2024 23:04:11 +0100 Subject: [PATCH] Apply basic auth to whole server --- internal/handlers/basicauth.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/handlers/basicauth.go b/internal/handlers/basicauth.go index 52023ef..00bc84a 100644 --- a/internal/handlers/basicauth.go +++ b/internal/handlers/basicauth.go @@ -2,13 +2,12 @@ package handlers import ( "net/http" - "strings" ) // basicAuth is a middleware that performs basic authentication. func (hs *Handlers) basicAuth(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "OPTIONS" && needsAuth(r.URL.Path) { + if r.Method != "OPTIONS" { if !hs.authenticate(r) { hs.unauthorized(w) return @@ -20,15 +19,15 @@ func (hs *Handlers) basicAuth(next http.Handler) http.Handler { } // needsAuth checks if the given path requires authentication. -func needsAuth(path string) bool { - authenticatedPaths := []string{"/http/", "/dav/", "/infuse/"} - for _, p := range authenticatedPaths { - if strings.HasPrefix(path, p) { - return true - } - } - return false -} +// func needsAuth(path string) bool { +// authenticatedPaths := []string{"/http/", "/dav/", "/infuse/"} +// for _, p := range authenticatedPaths { +// if strings.HasPrefix(path, p) { +// return true +// } +// } +// return false +// } // authenticate performs the basic authentication check. func (hs *Handlers) authenticate(r *http.Request) bool {