Major changes: - Add Go backend (backend/) with microservices architecture - Enhanced master-agents-svc: reranker, content-classifier, stealth-crawler, proxy-manager, media-search, fastClassifier, language detection - New web-svc widgets: KnowledgeCard, ProductCard, ProfileCard, VideoCard, UnifiedCard, CardGallery, InlineImageGallery, SourcesPanel, RelatedQuestions - Improved discover-svc with discover-db integration - Docker deployment improvements (Caddyfile, vendor.sh, BUILD.md) - Library-svc: project_id schema migration - Remove deprecated finance-svc and travel-svc - Localization improvements across services Made-with: Cursor
51 lines
872 B
Go
51 lines
872 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type AuthConfig struct {
|
|
RequireAuth bool
|
|
SkipPaths []string
|
|
}
|
|
|
|
func Auth(config AuthConfig) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
if !config.RequireAuth {
|
|
return c.Next()
|
|
}
|
|
|
|
path := c.Path()
|
|
for _, skip := range config.SkipPaths {
|
|
if strings.HasPrefix(path, skip) {
|
|
return c.Next()
|
|
}
|
|
}
|
|
|
|
auth := c.Get("Authorization")
|
|
if auth == "" {
|
|
return c.Status(401).JSON(fiber.Map{
|
|
"error": "Unauthorized",
|
|
})
|
|
}
|
|
|
|
if !strings.HasPrefix(auth, "Bearer ") {
|
|
return c.Status(401).JSON(fiber.Map{
|
|
"error": "Invalid authorization format",
|
|
})
|
|
}
|
|
|
|
return c.Next()
|
|
}
|
|
}
|
|
|
|
func ExtractToken(c *fiber.Ctx) string {
|
|
auth := c.Get("Authorization")
|
|
if strings.HasPrefix(auth, "Bearer ") {
|
|
return strings.TrimPrefix(auth, "Bearer ")
|
|
}
|
|
return ""
|
|
}
|