From ca98b7da73e641db023af03b943acdad8d7b822b Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 21 May 2025 22:27:24 +0200 Subject: [PATCH] feat: add /token/test route This new route returns 200 if a valid bearer token was presented. It does not return any information about the user. --- pkg/routes/api/v1/token_check.go | 6 ++++++ pkg/routes/api_tokens.go | 4 ++++ pkg/routes/routes.go | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/routes/api/v1/token_check.go b/pkg/routes/api/v1/token_check.go index 027cc863a..d7abc7b10 100644 --- a/pkg/routes/api/v1/token_check.go +++ b/pkg/routes/api/v1/token_check.go @@ -18,6 +18,7 @@ package v1 import ( "fmt" + "net/http" "code.vikunja.io/api/pkg/models" "github.com/golang-jwt/jwt/v5" @@ -33,3 +34,8 @@ func CheckToken(c echo.Context) error { return c.JSON(418, models.Message{Message: "🍵"}) } + +// TestToken returns a simple test message. Used for testing purposes. +func TestToken(c echo.Context) error { + return c.JSON(http.StatusOK, models.Message{Message: "ok"}) +} diff --git a/pkg/routes/api_tokens.go b/pkg/routes/api_tokens.go index 0e57d74a0..1d8323c27 100644 --- a/pkg/routes/api_tokens.go +++ b/pkg/routes/api_tokens.go @@ -48,6 +48,10 @@ func SetupTokenMiddleware() echo.MiddlewareFunc { return true } + if c.Request().URL.Path == "/api/v1/token/test" { + return true + } + err := checkAPITokenAndPutItInContext(s, c) return err == nil } diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index 20c35c1c2..af7904fba 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -285,7 +285,8 @@ func registerAPIRoutes(a *echo.Group) { // Middleware to collect metrics setupMetricsMiddleware(a) - a.POST("/tokenTest", apiv1.CheckToken) + a.GET("/token/test", apiv1.TestToken) + a.POST("/token/test", apiv1.CheckToken) a.GET("/routes", models.GetAvailableAPIRoutesForToken) // User stuff