From a9ce86f9a33cf54044f060b77aed594caae97ce1 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 10 Dec 2022 10:51:57 +0000 Subject: [PATCH] lib/http: add UsingAuth method --- lib/http/server.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/http/server.go b/lib/http/server.go index 253bdc60e..5e76e9615 100644 --- a/lib/http/server.go +++ b/lib/http/server.go @@ -144,6 +144,7 @@ type Server struct { cfg Config template *TemplateConfig htmlTemplate *template.Template + usingAuth bool // set if we are using auth middleware } // Option allows customizing the server @@ -272,19 +273,23 @@ func NewServer(ctx context.Context, options ...Option) (*Server, error) { func (s *Server) initAuth() { if s.auth.CustomAuthFn != nil { + s.usingAuth = true s.mux.Use(MiddlewareAuthCustom(s.auth.CustomAuthFn, s.auth.Realm)) return } if s.auth.HtPasswd != "" { + s.usingAuth = true s.mux.Use(MiddlewareAuthHtpasswd(s.auth.HtPasswd, s.auth.Realm)) return } if s.auth.BasicUser != "" { + s.usingAuth = true s.mux.Use(MiddlewareAuthBasic(s.auth.BasicUser, s.auth.BasicPass, s.auth.Realm, s.auth.Salt)) return } + s.usingAuth = false } func (s *Server) initTemplate() error { @@ -426,3 +431,8 @@ func (s *Server) URLs() []string { } return out } + +// UsingAuth returns true if authentication is required +func (s *Server) UsingAuth() bool { + return s.usingAuth +}