Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/middlewares/authenticated_middlesare.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/middlewares/authenticated_middlesare.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/middlewares/authenticated_middlesare.go
-
curl -L -o authenticated_middlesare.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/middlewares/authenticated_middlesare.go
1.03 kB
| package middlewares | |
| import ( | |
| "github.com/NdoleStudio/httpsms/pkg/entities" | |
| "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
| "github.com/gofiber/fiber/v3" | |
| ) | |
| const ( | |
| authHeaderBearer = "Authorization" | |
| authHeaderAPIKey = "x-api-key" | |
| bearerScheme = "Bearer" | |
| ) | |
| const ( | |
| // ContextKeyAuthUserID is the context key used to store the ID of an authenticated user | |
| ContextKeyAuthUserID = "auth.user.id" | |
| ) | |
| // Authenticated checks if the request is authenticated | |
| func Authenticated(tracer telemetry.Tracer) fiber.Handler { | |
| return func(c fiber.Ctx) error { | |
| _, span := tracer.StartFromFiberCtx(c, "middlewares.Authenticated") | |
| defer span.End() | |
| if tokenUser, ok := c.Locals(ContextKeyAuthUserID).(entities.AuthContext); !ok || tokenUser.IsNoop() { | |
| return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{ | |
| "status": "error", | |
| "message": "You are not authorized to carry out this request.", | |
| "data": "Make sure your API key is set in the [x-api-key] header in the request", | |
| }) | |
| } | |
| return c.Next() | |
| } | |
| } | |