mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
9af84c8ed6
Replace c.JSON(200, response.Err) and middleware gin.H bypasses with response.Abort* helpers so errors flow through Gin Error chain and ErrorHandlerMiddleware for OTel trace correlation. Split oauth/sources.go into domain-focused files and decompose upload into handler/filesrv/stats/task/cache/storage/util subpackages with a root facade preserving existing import paths.
34 lines
757 B
Go
34 lines
757 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cap
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/common/response"
|
|
)
|
|
|
|
// VerifyMiddleware returns a Gin middleware that checks and consumes the X-Cap-Token header.
|
|
func VerifyMiddleware(mgr *Manager, scope string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if !ProtectionEnabled(c.Request.Context()) {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
token := c.GetHeader("X-Cap-Token")
|
|
if token == "" {
|
|
response.AbortUnauthorized(c, errCapTokenMissing)
|
|
return
|
|
}
|
|
|
|
valid, err := mgr.VerifyToken(c.Request.Context(), token, scope)
|
|
if err != nil || !valid {
|
|
response.AbortUnauthorized(c, errCapTokenInvalidOrExpired)
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
} |