Files
ghproxy/auth/auth-parameters.go
wjqserver 4fd47812f7 25w19a
2025-03-16 21:03:28 +08:00

29 lines
612 B
Go

package auth
import (
"fmt"
"ghproxy/config"
"github.com/gin-gonic/gin"
)
func AuthParametersHandler(c *gin.Context, cfg *config.Config) (isValid bool, err error) {
if !cfg.Auth.Enabled {
return true, nil
}
authToken := c.Query("auth_token")
logDebug("%s %s %s %s %s AUTH_TOKEN: %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto, authToken)
if authToken == "" {
return false, fmt.Errorf("Auth token not found")
}
isValid = authToken == cfg.Auth.AuthToken
if !isValid {
return false, fmt.Errorf("Auth token invalid")
}
return isValid, nil
}