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