second commit

This commit is contained in:
Rogee
2026-06-04 15:44:48 +08:00
parent 4db6efb3a7
commit 8ac150bc7b
1275 changed files with 286124 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gochat/gochat/internal/auth"
"github.com/gochat/gochat/pkg/response"
)
// WebhookAuth validates webhook tokens for channel callback routes.
// Reference: P2E §4 — webhook authentication per channel type
func WebhookAuth(registry *auth.WebhookTokenRegistry) gin.HandlerFunc {
return func(c *gin.Context) {
channelType := c.Param("channel_type")
identifier := c.Param("identifier")
valid, err := registry.Validate(channelType, identifier, c.Request)
if err != nil || !valid {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "Invalid webhook token")
return
}
c.Next()
}
}