ghost-listmonk-connector/middleware/auth.go
troneras 1fd7dad8e4 # This is a combination of 2 commits.
# This is the 1st commit message:

first commit

# This is the commit message #2:

fixed cache
2024-08-21 02:08:01 +02:00

24 lines
408 B
Go

package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
func APIKeyAuth(validAPIKey string) gin.HandlerFunc {
return func(c *gin.Context) {
apiKey := c.GetHeader("Authorization")
if apiKey == "" {
apiKey = c.Query("api_key")
}
if apiKey != "Bearer "+validAPIKey {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid API key"})
c.Abort()
return
}
c.Next()
}
}