mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
25w20a
This commit is contained in:
parent
ac7e1e43b5
commit
a92bbb7fb6
22 changed files with 685 additions and 316 deletions
|
|
@ -4,20 +4,21 @@ import (
|
|||
"ghproxy/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AuthPassThrough(c *gin.Context, cfg *config.Config, req *http.Request) {
|
||||
func AuthPassThrough(c *app.RequestContext, cfg *config.Config, req *http.Request) {
|
||||
if cfg.Auth.PassThrough {
|
||||
token := c.Query("token")
|
||||
if token != "" {
|
||||
logDebug("%s %s %s %s %s Auth-PassThrough: token %s", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, token)
|
||||
logDebug("%s %s %s %s %s Auth-PassThrough: token %s", c.ClientIP(), c.Request.Method, string(c.Path()), c.GetHeader, c.Request.Header.GetProtocol(), token)
|
||||
switch cfg.Auth.AuthMethod {
|
||||
case "parameters":
|
||||
if !cfg.Auth.Enabled {
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
} else {
|
||||
logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, string(c.Path()), c.GetHeader, c.Request.Header.GetProtocol())
|
||||
// 500 Internal Server Error
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Conflict Auth Method"})
|
||||
return
|
||||
|
|
@ -27,7 +28,7 @@ func AuthPassThrough(c *gin.Context, cfg *config.Config, req *http.Request) {
|
|||
req.Header.Set("Authorization", "token "+token)
|
||||
}
|
||||
default:
|
||||
logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, string(c.Path()), c.GetHeader, c.Request.Header.GetProtocol())
|
||||
// 500 Internal Server Error
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Invalid Auth Method / Auth Method is not be set"})
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue