2018-06-11 15:13:19 +02:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-09-10 12:01:38 +02:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2019-03-21 14:20:14 +13:00
|
|
|
"github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/http/proxy"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2020-06-16 10:58:16 +03:00
|
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
2018-06-11 15:13:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle authentication operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2020-05-20 17:23:15 +12:00
|
|
|
DataStore portainer.DataStore
|
|
|
|
CryptoService portainer.CryptoService
|
|
|
|
JWTService portainer.JWTService
|
|
|
|
LDAPService portainer.LDAPService
|
|
|
|
ProxyManager *proxy.Manager
|
2020-06-16 10:58:16 +03:00
|
|
|
AuthorizationService *authorization.Service
|
2018-06-11 15:13:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage authentication operations.
|
2020-06-09 12:55:36 +03:00
|
|
|
func NewHandler(bouncer *security.RequestBouncer, rateLimiter *security.RateLimiter) *Handler {
|
2018-06-11 15:13:19 +02:00
|
|
|
h := &Handler{
|
2020-06-09 12:55:36 +03:00
|
|
|
Router: mux.NewRouter(),
|
2018-06-11 15:13:19 +02:00
|
|
|
}
|
2019-01-16 17:24:58 +02:00
|
|
|
|
2019-01-18 10:13:33 +02:00
|
|
|
h.Handle("/auth/oauth/validate",
|
2019-01-18 10:15:02 +02:00
|
|
|
rateLimiter.LimitAccess(bouncer.PublicAccess(httperror.LoggerHandler(h.validateOAuth)))).Methods(http.MethodPost)
|
2018-06-11 15:13:19 +02:00
|
|
|
h.Handle("/auth",
|
|
|
|
rateLimiter.LimitAccess(bouncer.PublicAccess(httperror.LoggerHandler(h.authenticate)))).Methods(http.MethodPost)
|
|
|
|
|
|
|
|
return h
|
|
|
|
}
|