mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 07:06:36 +08:00
[优化] go 引用调整
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rain-kl/openflare/openflare-server/common/response"
|
||||
"github.com/rain-kl/openflare/openflare-server/service"
|
||||
)
|
||||
|
||||
// RelayAuth authenticates Relay requests using the shared agent token,
|
||||
// and verifies the node is a tunnel_relay type.
|
||||
func RelayAuth() func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
token := c.GetHeader("X-Agent-Token")
|
||||
node, err := service.AuthenticateAccessToken(token)
|
||||
if err != nil {
|
||||
response.RespondUnauthorized(c, "无权进行此操作,Agent Token 无效")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
if node.NodeType != "tunnel_relay" {
|
||||
response.RespondForbidden(c, "此节点不是 TunnelRelay 类型")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Set("relay_node", node)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user