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.
This commit is contained in:
kolaente
2025-05-21 22:27:24 +02:00
parent 19419a9f11
commit ca98b7da73
3 changed files with 12 additions and 1 deletions

View File

@@ -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"})
}

View File

@@ -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
}

View File

@@ -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