From 999cc2bcd8f446bc94a48e6eb1b60e06abe790df Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 27 Oct 2024 00:14:42 +0800 Subject: [PATCH] :bug: Fix auth context middleware force provide token --- pkg/internal/auth/http.go | 4 ++++ pkg/internal/http/api/index.go | 2 -- pkg/internal/http/server.go | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/internal/auth/http.go b/pkg/internal/auth/http.go index 1e419ee..24d4334 100644 --- a/pkg/internal/auth/http.go +++ b/pkg/internal/auth/http.go @@ -6,6 +6,10 @@ import ( func ContextMiddleware(c *fiber.Ctx) error { atk := tokenExtract(c) + if len(atk) == 0 { + return c.Next() + } + c.Locals("nex_in_token", atk) if claims, err := tokenRead(atk); err == nil && claims != nil { diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go index 2e0532d..c7aedda 100644 --- a/pkg/internal/http/api/index.go +++ b/pkg/internal/http/api/index.go @@ -8,8 +8,6 @@ import ( ) func MapAPIs(app *fiber.App) { - app.Use(auth.ContextMiddleware) - // Some built-in public-accessible APIs wellKnown := app.Group("/.well-known").Name("Well Known") { diff --git a/pkg/internal/http/server.go b/pkg/internal/http/server.go index 6a76101..4aaf9fe 100644 --- a/pkg/internal/http/server.go +++ b/pkg/internal/http/server.go @@ -1,6 +1,7 @@ package server import ( + "git.solsynth.dev/hypernet/nexus/pkg/internal/auth" "git.solsynth.dev/hypernet/nexus/pkg/internal/http/api" "github.com/goccy/go-json" "github.com/gofiber/fiber/v2" @@ -42,6 +43,8 @@ func NewServer() *HTTPApp { Output: log.Logger, })) + app.Use(auth.ContextMiddleware) + api.MapAPIs(app) return &HTTPApp{app}