From a785adfafa5110d7aead87f5f8ffb3cd8205551a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 30 Oct 2024 23:26:39 +0800 Subject: [PATCH] :bug: Bug fixes on auth --- pkg/internal/auth/http.go | 8 ++------ pkg/internal/http/api/forward.go | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/internal/auth/http.go b/pkg/internal/auth/http.go index d1a2659..5eb3aeb 100644 --- a/pkg/internal/auth/http.go +++ b/pkg/internal/auth/http.go @@ -18,7 +18,7 @@ func ContextMiddleware(c *fiber.Ctx) error { return err } } else if err != nil { - c.Locals("nex_auth_error", err) + return fiber.NewError(fiber.StatusUnauthorized, err.Error()) } return c.Next() @@ -26,11 +26,7 @@ func ContextMiddleware(c *fiber.Ctx) error { func ValidatorMiddleware(c *fiber.Ctx) error { if c.Locals("nex_principal") == nil { - if err, ok := c.Locals("nex_auth_error").(error); ok { - return fiber.NewError(fiber.StatusUnauthorized, err.Error()) - } else { - return fiber.NewError(fiber.StatusUnauthorized, "unauthorized") - } + return fiber.NewError(fiber.StatusUnauthorized, "unauthorized") } return c.Next() diff --git a/pkg/internal/http/api/forward.go b/pkg/internal/http/api/forward.go index 03693aa..9a6b706 100644 --- a/pkg/internal/http/api/forward.go +++ b/pkg/internal/http/api/forward.go @@ -29,9 +29,9 @@ func forwardService(c *fiber.Ctx) error { url = *service.HttpAddr + url if tk, ok := c.Locals("nex_token").(string); ok { - c.Set(fiber.HeaderAuthorization, fmt.Sprintf("Bearer %s", tk)) + c.Request().Header.Set(fiber.HeaderAuthorization, fmt.Sprintf("Bearer %s", tk)) } else { - c.Set(fiber.HeaderAuthorization, "") + c.Request().Header.Del(fiber.HeaderAuthorization) } return proxy.Do(c, url)