From 9b01666ec6c41f5487cfc6c381b3937f1fe53a16 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 1 Sep 2024 19:25:24 +0200 Subject: [PATCH] chore(web): use web auth factory directly --- pkg/routes/routes.go | 5 ----- pkg/web/handler/config.go | 7 ------- pkg/web/handler/create.go | 3 ++- pkg/web/handler/delete.go | 3 ++- pkg/web/handler/read_all.go | 3 ++- pkg/web/handler/read_one.go | 3 ++- pkg/web/handler/update.go | 3 ++- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index 1d3f0cbfe..86b336ccb 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -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 diff --git a/pkg/web/handler/config.go b/pkg/web/handler/config.go index 197d17aa8..e84448b28 100644 --- a/pkg/web/handler/config.go +++ b/pkg/web/handler/config.go @@ -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 diff --git a/pkg/web/handler/create.go b/pkg/web/handler/create.go index 341fc69d6..fc12e84d9 100644 --- a/pkg/web/handler/create.go +++ b/pkg/web/handler/create.go @@ -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.") } diff --git a/pkg/web/handler/delete.go b/pkg/web/handler/delete.go index c60b35cb5..c6e8e7525 100644 --- a/pkg/web/handler/delete.go +++ b/pkg/web/handler/delete.go @@ -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) } diff --git a/pkg/web/handler/read_all.go b/pkg/web/handler/read_all.go index ac0e1bd15..f41dd82ce 100644 --- a/pkg/web/handler/read_all.go +++ b/pkg/web/handler/read_all.go @@ -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.") } diff --git a/pkg/web/handler/read_one.go b/pkg/web/handler/read_one.go index 18cfccb1e..113da9f68 100644 --- a/pkg/web/handler/read_one.go +++ b/pkg/web/handler/read_one.go @@ -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.") } diff --git a/pkg/web/handler/update.go b/pkg/web/handler/update.go index 7d34fccd7..f6339c4b4 100644 --- a/pkg/web/handler/update.go +++ b/pkg/web/handler/update.go @@ -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.") }