mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
24w23a
This commit is contained in:
parent
85896ffbfe
commit
c55ae4a5b7
11 changed files with 102 additions and 25 deletions
31
auth/auth-parameters.go
Normal file
31
auth/auth-parameters.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AuthParametersHandler(c *gin.Context, cfg *config.Config) (isValid bool, err string) {
|
||||
if !cfg.Auth.Enabled {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
authToken := c.Query("auth_token")
|
||||
logInfo("%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 == "" {
|
||||
err := "Auth token == nil"
|
||||
return false, err
|
||||
}
|
||||
|
||||
isValid = authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
err := fmt.Sprintf("Auth token incorrect: %s", authToken)
|
||||
return false, err
|
||||
}
|
||||
|
||||
logInfo("auth SUCCESS: %t", isValid)
|
||||
return isValid, ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue