mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
9f8890d159
- Declared module Wavelet in backend/go.mod - Replaced github.com/Rain-kl/Wavelet/ with clean Wavelet/ import paths across backend codebase - Updated architecture guards, Makefile, swagger, and build tests - 100% passed all tests, lint checks, and binary compilation
39 lines
821 B
Go
39 lines
821 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cap
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"Wavelet/pkg/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
|
|
}
|
|
if mgr == nil {
|
|
response.AbortUnauthorized(c, errCapTokenInvalidOrExpired)
|
|
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()
|
|
}
|
|
}
|