mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-12 01:59:34 -05:00
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:
@@ -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"})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user