[break] change auth config & add auth key

This commit is contained in:
wjqserver 2025-04-01 18:32:45 +08:00
parent 978ece6fa0
commit 395f641468
8 changed files with 50 additions and 27 deletions

View file

@ -12,14 +12,20 @@ func AuthParametersHandler(c *app.RequestContext, cfg *config.Config) (isValid b
return true, nil
}
authToken := c.Query("auth_token")
var authToken string
if cfg.Auth.Key != "" {
authToken = c.Query(cfg.Auth.Key)
} else {
authToken = c.Query("auth_token")
}
logDebug("%s %s %s %s %s AUTH_TOKEN: %s", c.ClientIP(), c.Method(), string(c.Path()), c.Request.Header.UserAgent(), c.Request.Header.GetProtocol(), authToken)
if authToken == "" {
return false, fmt.Errorf("Auth token not found")
}
isValid = authToken == cfg.Auth.AuthToken
isValid = authToken == cfg.Auth.Token
if !isValid {
return false, fmt.Errorf("Auth token invalid")
}