This commit is contained in:
Samir Patel 2021-12-16 20:33:23 -06:00
parent 52625c70ab
commit b37f13e5c5
2 changed files with 15 additions and 11 deletions

View file

@ -29,7 +29,7 @@ import (
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
pilosa "github.com/molecula/featurebase/v2"
auth "github.com/molecula/featurebase/v2/authenticate"
"github.com/molecula/featurebase/v2/authn"
"github.com/molecula/featurebase/v2/encoding/proto"
"github.com/molecula/featurebase/v2/ingest"
"github.com/molecula/featurebase/v2/logger"
@ -69,7 +69,7 @@ type Handler struct {
pprofCPUProfileBuffer *bytes.Buffer
auth *auth.Auth
auth *authn.Auth
}
// externalPrefixFlag denotes endpoints that are intended to be exposed to clients.
@ -116,7 +116,7 @@ func OptHandlerAPI(api *pilosa.API) handlerOption {
}
}
func OptHandlerAuth(auth *auth.Auth) handlerOption {
func OptHandlerAuth(auth *authn.Auth) handlerOption {
return func(h *Handler) error {
h.auth = auth
return nil
@ -3369,7 +3369,7 @@ func (h *Handler) handlePostRestore(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleLogin(w http.ResponseWriter, r *http.Request) {
if h.auth == nil {
http.Error(w, fmt.Sprintf("Trying to login but authentication is off."), http.StatusBadRequest)
http.Error(w, "Trying to login but authentication is off.", http.StatusBadRequest)
return
}
h.logger.Infof("Handle Login Begin")
@ -3384,7 +3384,7 @@ func (h *Handler) handleLogin(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleRedirect(w http.ResponseWriter, r *http.Request) {
if h.auth == nil {
http.Error(w, fmt.Sprintf("Authentication is off."), http.StatusBadRequest)
http.Error(w, "Authentication is off.", http.StatusBadRequest)
return
}
h.auth.Redirect(w, r)
@ -3392,7 +3392,7 @@ func (h *Handler) handleRedirect(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleCheckAuthentication(w http.ResponseWriter, r *http.Request) {
if h.auth == nil {
http.Error(w, fmt.Sprintf("Trying to authenticate but authentication is off."), http.StatusBadRequest)
http.Error(w, "Trying to authenticate but authentication is off.", http.StatusBadRequest)
return
}
groups := h.auth.Authenticate(w, r)
@ -3409,7 +3409,7 @@ func (h *Handler) handleCheckAuthentication(w http.ResponseWriter, r *http.Reque
func (h *Handler) handleUserInfo(w http.ResponseWriter, r *http.Request) {
if h.auth == nil {
http.Error(w, fmt.Sprintf("Authentication is off."), http.StatusBadRequest)
http.Error(w, "Authentication is off.", http.StatusBadRequest)
return
}
if err := json.NewEncoder(w).Encode(h.auth.GetUserInfo(r)); err != nil {
@ -3419,7 +3419,7 @@ func (h *Handler) handleUserInfo(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleLogout(w http.ResponseWriter, r *http.Request) {
if h.auth == nil {
http.Error(w, fmt.Sprintf("Trying to log out but authentication is off."), http.StatusBadRequest)
http.Error(w, "Trying to log out but authentication is off.", http.StatusBadRequest)
return
}
h.auth.Logout(w, r)

View file

@ -29,7 +29,7 @@ import (
"golang.org/x/sync/errgroup"
pilosa "github.com/molecula/featurebase/v2"
auth "github.com/molecula/featurebase/v2/authenticate"
"github.com/molecula/featurebase/v2/authn"
"github.com/molecula/featurebase/v2/boltdb"
"github.com/molecula/featurebase/v2/encoding/proto"
petcd "github.com/molecula/featurebase/v2/etcd"
@ -83,7 +83,7 @@ type Command struct {
serverOptions []pilosa.ServerOption
auth *auth.Auth
auth *authn.Auth
}
type CommandOption func(c *Command) error
@ -525,7 +525,11 @@ func (m *Command) SetupServer() error {
if m.Config.Auth.Enable {
m.Config.MustValidateAuth()
ac := m.Config.Auth
m.auth, _ = auth.NewAuth(m.logger, m.listenURI.String(), ac.Scopes, ac.AuthorizeURL, ac.TokenURL, ac.GroupEndpointURL, ac.ClientId, ac.ClientSecret, ac.HashKey, ac.BlockKey)
m.auth, err = authn.NewAuth(m.logger, m.listenURI.String(), ac.Scopes, ac.AuthorizeURL, ac.TokenURL, ac.GroupEndpointURL, ac.ClientId, ac.ClientSecret, ac.HashKey, ac.BlockKey)
if err != nil {
return errors.Wrap(err, "instantiating authN object")
}
}
m.logger.Infof("Before Handler %+v", m.auth)