- Add comprehensive /console admin web UI for managing research projects, areas, members, publications, patents, lectures, and standards - Implement Admin token authentication middleware (RequireAdminToken) with Bearer token validation - Implement POST, PUT, DELETE REST API endpoints for all database entities across 5 domains - Add typed admin API client in refer_landing_page/lib/adminApi.ts with localStorage session persistence - Enhance E2E test runner to manage backend server lifecycle during automated tests - Pass all 12 quality gates cleanly with unanimous reviewer PASS verdicts
35 lines
757 B
Go
35 lines
757 B
Go
package httpx
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RequireAdminToken returns a Gin middleware that validates Bearer <token> against the configured admin token.
|
|
func RequireAdminToken(adminToken string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if adminToken == "" {
|
|
Unauthorized(c, "Admin API is disabled: ADMIN_TOKEN is not configured")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
auth := c.GetHeader("Authorization")
|
|
if auth == "" {
|
|
Unauthorized(c, "Missing Authorization header")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
parts := strings.SplitN(auth, " ", 2)
|
|
if len(parts) != 2 || !strings.EqualFold(parts[0], "Bearer") || parts[1] != adminToken {
|
|
Unauthorized(c, "Invalid admin bearer token")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
}
|