From 213572bb7855977f5d67a9ccee9e6cb532d5aee1 Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Wed, 15 Dec 2021 14:51:45 -0600 Subject: [PATCH] add logout and userinfo endpoints --- http/handler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/http/handler.go b/http/handler.go index d03182e29..83d2654a2 100644 --- a/http/handler.go +++ b/http/handler.go @@ -29,7 +29,7 @@ import ( "github.com/gorilla/handlers" "github.com/gorilla/mux" pilosa "github.com/molecula/featurebase/v2" - "github.com/molecula/featurebase/v2/auth" + auth "github.com/molecula/featurebase/v2/authenticate" "github.com/molecula/featurebase/v2/encoding/proto" "github.com/molecula/featurebase/v2/ingest" "github.com/molecula/featurebase/v2/logger" @@ -458,8 +458,10 @@ func newRouter(handler *Handler) http.Handler { router.HandleFunc("/cpu-profile/stop", handler.handleCPUProfileStop).Methods("GET").Name("CPUProfileStop") router.HandleFunc("/login", handler.handleLogin).Methods("GET").Name("Login") + router.HandleFunc("/logout", handler.handleLogout).Methods("GET").Name("Login") router.HandleFunc("/redirect", handler.handleRedirect).Methods("GET").Name("Redirect") router.HandleFunc("/auth", handler.handleCheckAuthentication).Methods("GET").Name("CheckAuthentication") + router.HandleFunc("/userinfo", handler.handleUserInfo).Methods("GET").Name("UserInfo") // Endpoints to support lattice UI embedded via statik. // The messiness here reflects the fact that assets live in a nontrivial @@ -3392,3 +3394,13 @@ func (h *Handler) handleCheckAuthentication(w http.ResponseWriter, r *http.Reque w.Write([]byte("OK")) //nolint:errcheck } + +func (h *Handler) handleUserInfo(w http.ResponseWriter, r *http.Request) { + if err := json.NewEncoder(w).Encode(h.auth.GetUserInfo(r)); err != nil { + h.logger.Errorf("writing user info: %s", err) + } +} + +func (h *Handler) handleLogout(w http.ResponseWriter, r *http.Request) { + h.auth.Logout(w, r) +}