From 819adbbb708076bcf9d3ee6443c704303aad5a80 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Thu, 30 Jan 2020 19:08:14 -0600 Subject: refactor auth middleware --- main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index d719149..48c3efa 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( func main() { opts := config.NewOpts() ch := web.NewCertHandler(opts.CaCrt, opts.CaKey) + authenticator := auth.GetAuthenticator(opts, false) /* protected routes */ @@ -19,8 +20,8 @@ func main() { http.HandleFunc("/3/refresh-token", auth.RefreshAuthMiddleware(opts.Auth)) */ - http.Handle("/3/cert", auth.RestrictedMiddleware(opts, ch)) - http.HandleFunc("/3/auth", auth.AuthenticatorMiddleware(opts)) + http.HandleFunc("/3/auth", web.AuthMiddleware(authenticator.CheckCredentials, opts)) + http.Handle("/3/cert", web.RestrictedMiddleware(authenticator.NeedsCredentials, ch.CertResponder, opts)) /* static files */ @@ -36,7 +37,7 @@ func main() { pstr := ":" + opts.Port log.Println("Listening in port", opts.Port) - if opts.tls == true { + if opts.Tls == true { log.Fatal(http.ListenAndServeTLS(pstr, opts.TlsCrt, opts.TlsKey, nil)) } else { log.Fatal(http.ListenAndServe(pstr, nil)) -- cgit v1.2.3