mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
28 lines
612 B
Go
28 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
|
|
}
|