24 lines
512 B
Go
24 lines
512 B
Go
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)
|
|
}
|
|
}
|