feat: improve api token verification compatibility

This commit is contained in:
Marvin Zhang
2024-12-11 17:52:51 +08:00
parent 2a7aa76e5e
commit 30767754a0

View File

@@ -9,6 +9,7 @@ import (
"github.com/crawlab-team/crawlab/core/utils"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"strings"
)
func AuthorizationMiddleware() gin.HandlerFunc {
@@ -28,6 +29,9 @@ func AuthorizationMiddleware() gin.HandlerFunc {
// token string
tokenStr := c.GetHeader("Authorization")
if strings.HasPrefix(tokenStr, "Bearer ") {
tokenStr = strings.Replace(tokenStr, "Bearer ", "", 1)
}
// validate token
u, err := userSvc.CheckToken(tokenStr)