Add more flags to customize auth
This commit is contained in:
@@ -26,16 +26,19 @@ func (s *Server) HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if s.options.Auth.Enabled {
|
||||||
|
auth := s.options.Auth.Get()
|
||||||
secret := r.PostFormValue("secret")
|
secret := r.PostFormValue("secret")
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "auth",
|
Name: "auth",
|
||||||
Value: secret,
|
Value: secret,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: 3600,
|
MaxAge: auth.MaxAge,
|
||||||
Secure: false,
|
Secure: auth.Secure,
|
||||||
HttpOnly: false,
|
HttpOnly: false,
|
||||||
SameSite: http.SameSiteLaxMode,
|
SameSite: http.SameSiteLaxMode,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ type AuthOptions struct {
|
|||||||
// Secret Direct or Path to secret File
|
// Secret Direct or Path to secret File
|
||||||
Secret string
|
Secret string
|
||||||
LoadType AuthType
|
LoadType AuthType
|
||||||
|
Secure bool
|
||||||
|
MaxAge int
|
||||||
}
|
}
|
||||||
|
|
||||||
type TlsOptions struct {
|
type TlsOptions struct {
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -32,6 +32,8 @@ var (
|
|||||||
debugFlag = flag.Bool("debug", false, "Activate debug Logs")
|
debugFlag = flag.Bool("debug", false, "Activate debug Logs")
|
||||||
prettyLogsFlag = flag.Bool("pretty", false, "Pretty pring Logs")
|
prettyLogsFlag = flag.Bool("pretty", false, "Pretty pring Logs")
|
||||||
logPathFlag = flag.String("log", "", "Path to logfile, stderr if default")
|
logPathFlag = flag.String("log", "", "Path to logfile, stderr if default")
|
||||||
|
maxAgeFlag = flag.Int("age", 3600, "Max age for login Session")
|
||||||
|
secureFlag = flag.Bool("secure", false, "Cookie secure?")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -88,6 +90,8 @@ func setupAuth() server.AuthOptions {
|
|||||||
authOptions.Secret = path
|
authOptions.Secret = path
|
||||||
authOptions.LoadType = server.File
|
authOptions.LoadType = server.File
|
||||||
}
|
}
|
||||||
|
authOptions.MaxAge = *maxAgeFlag
|
||||||
|
authOptions.Secure = *secureFlag
|
||||||
return authOptions
|
return authOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user