mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
24w06b
This commit is contained in:
parent
efeb940676
commit
0899397d2e
7 changed files with 263 additions and 212 deletions
33
auth/auth.go
Normal file
33
auth/auth.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *config.Config
|
||||
log = logger.Logw
|
||||
)
|
||||
|
||||
func AuthHandler(c *gin.Context) bool {
|
||||
// 如果身份验证未启用,直接返回 true
|
||||
if !cfg.Auth {
|
||||
log("auth PASS")
|
||||
return true
|
||||
}
|
||||
|
||||
// 获取 auth_token 参数
|
||||
authToken := c.Query("auth_token")
|
||||
log("auth_token: ", authToken)
|
||||
|
||||
// 验证 token
|
||||
isValid := authToken == cfg.AuthToken
|
||||
if !isValid {
|
||||
log("auth FAIL")
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue