This commit is contained in:
WJQSERVER 2024-09-27 15:18:47 +08:00
parent bb4e2d8ae7
commit 178d5f14c2
3 changed files with 27 additions and 13 deletions

View file

@ -7,26 +7,28 @@ import (
"github.com/gin-gonic/gin"
)
var (
cfg *config.Config
log = logger.Logw
)
var logw = logger.Logw
func AuthHandler(c *gin.Context) bool {
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
// 如果身份验证未启用,直接返回 true
if !cfg.Auth {
log("auth PASS")
logw("auth PASS")
return true
}
// 获取 auth_token 参数
authToken := c.Query("auth_token")
log("auth_token: ", authToken)
log("auth_token received: %s", authToken)
// 验证 token
if authToken == "" {
logw("auth FAIL: no auth_token provided")
return false
}
isValid := authToken == cfg.AuthToken
if !isValid {
log("auth FAIL")
logw("auth FAIL: invalid auth_token")
}
return isValid