Initial commit
This commit is contained in:
23
handlers/middleware.go
Normal file
23
handlers/middleware.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"git.sr.ht/~cwpearson/replicate-jump-server/config"
|
||||
)
|
||||
|
||||
// AuthMiddleware validates the bearer token
|
||||
func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
auth := c.Request().Header.Get("Authorization")
|
||||
expectedAuth := "Bearer " + config.Bearer()
|
||||
|
||||
if auth != expectedAuth {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid or missing bearer token")
|
||||
}
|
||||
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user