mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
27 lines
514 B
Go
27 lines
514 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func InternalAuthMiddleware(expectedToken string) gin.HandlerFunc {
|
|
expectedToken = strings.TrimSpace(expectedToken)
|
|
return func(c *gin.Context) {
|
|
if expectedToken == "" {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
token := strings.TrimSpace(c.GetHeader("X-Internal-Token"))
|
|
if token == "" || token != expectedToken {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid internal token"})
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|