forked from vikunja/vikunja
chore(web): use web auth factory directly
This commit is contained in:
parent
14c862d284
commit
9b01666ec6
@ -60,7 +60,6 @@ import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
"code.vikunja.io/api/pkg/modules/auth/openid"
|
||||
"code.vikunja.io/api/pkg/modules/background"
|
||||
backgroundHandler "code.vikunja.io/api/pkg/modules/background/handler"
|
||||
@ -76,7 +75,6 @@ import (
|
||||
apiv1 "code.vikunja.io/api/pkg/routes/api/v1"
|
||||
"code.vikunja.io/api/pkg/routes/caldav"
|
||||
"code.vikunja.io/api/pkg/version"
|
||||
"code.vikunja.io/api/pkg/web"
|
||||
"code.vikunja.io/api/pkg/web/handler"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
@ -119,9 +117,6 @@ func NewEcho() *echo.Echo {
|
||||
e.Validator = &CustomValidator{}
|
||||
|
||||
// Handler config
|
||||
handler.SetAuthProvider(&web.Auths{
|
||||
AuthObject: auth.GetAuthFromClaims,
|
||||
})
|
||||
handler.SetLoggingProvider(log.GetLogger())
|
||||
|
||||
return e
|
||||
|
@ -17,13 +17,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/web"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
// Config contains the config for the web handler
|
||||
type Config struct {
|
||||
AuthProvider *web.Auths
|
||||
LoggingProvider *logging.Logger
|
||||
}
|
||||
|
||||
@ -33,11 +31,6 @@ func init() {
|
||||
config = &Config{}
|
||||
}
|
||||
|
||||
// SetAuthProvider sets the auth provider in config
|
||||
func SetAuthProvider(provider *web.Auths) {
|
||||
config.AuthProvider = provider
|
||||
}
|
||||
|
||||
// SetLoggingProvider sets the logging provider in the config
|
||||
func SetLoggingProvider(logger *logging.Logger) {
|
||||
config.LoggingProvider = logger
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -47,7 +48,7 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Get the user to pass for later checks
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -47,7 +48,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check if the user has the right to delete
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
|
||||
vconfig "code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -34,7 +35,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||
// Get our model
|
||||
currentStruct := c.EmptyStruct()
|
||||
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -43,7 +44,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check rights
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -48,7 +49,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check if the user has the right to do that
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user