mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
[break] change auth config & add auth key
This commit is contained in:
parent
978ece6fa0
commit
395f641468
8 changed files with 50 additions and 27 deletions
|
|
@ -12,13 +12,19 @@ func AuthHeaderHandler(c *app.RequestContext, cfg *config.Config) (isValid bool,
|
|||
return true, nil
|
||||
}
|
||||
// 获取"GH-Auth"的值
|
||||
authToken := string(c.GetHeader("GH-Auth"))
|
||||
var authToken string
|
||||
if cfg.Auth.Key != "" {
|
||||
authToken = string(c.GetHeader(cfg.Auth.Key))
|
||||
|
||||
} else {
|
||||
authToken = string(c.GetHeader("GH-Auth"))
|
||||
}
|
||||
logDebug("%s %s %s %s %s AUTH_TOKEN: %s", 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 incorrect")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,17 @@ func Init(cfg *config.Config) {
|
|||
}
|
||||
|
||||
func AuthHandler(ctx context.Context, c *app.RequestContext, cfg *config.Config) (isValid bool, err error) {
|
||||
if cfg.Auth.AuthMethod == "parameters" {
|
||||
if cfg.Auth.Method == "parameters" {
|
||||
isValid, err = AuthParametersHandler(c, cfg)
|
||||
return isValid, err
|
||||
} else if cfg.Auth.AuthMethod == "header" {
|
||||
} else if cfg.Auth.Method == "header" {
|
||||
isValid, err = AuthHeaderHandler(c, cfg)
|
||||
return isValid, err
|
||||
} else if cfg.Auth.AuthMethod == "" {
|
||||
} else if cfg.Auth.Method == "" {
|
||||
logError("Auth method not set")
|
||||
return true, nil
|
||||
} else {
|
||||
logError("Auth method not supported")
|
||||
return false, fmt.Errorf(fmt.Sprintf("Auth method %s not supported", cfg.Auth.AuthMethod))
|
||||
return false, fmt.Errorf(fmt.Sprintf("Auth method %s not supported", cfg.Auth.Method))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue