diff --git a/docker-compose.yml b/docker-compose.yml index 391df1b..b931a36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,4 +10,7 @@ services: - TZ=Asia/Shanghai - OAUTH_CLIENT_ID=your_client_id - OAUTH_CLIENT_SECRET=your_client_secret + #填写公网访问的地址, 需要跟CZL Connect保持一致. + #选填, 不填为自动获取 + - OAUTH_REDIRECT_URI=https://localhost:3336/admin/api/oauth/callback restart: always \ No newline at end of file diff --git a/internal/handler/auth.go b/internal/handler/auth.go index c0c8695..486cc4d 100644 --- a/internal/handler/auth.go +++ b/internal/handler/auth.go @@ -150,11 +150,15 @@ func (h *ProxyHandler) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc { // getCallbackURL 从请求中获取回调地址 func getCallbackURL(r *http.Request) string { - scheme := "http" - if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" { - scheme = "https" + if os.Getenv("OAUTH_REDIRECT_URI") != "" { + return os.Getenv("OAUTH_REDIRECT_URI") + } else { + scheme := "http" + if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" { + scheme = "https" + } + return fmt.Sprintf("%s://%s/admin/api/oauth/callback", scheme, r.Host) } - return fmt.Sprintf("%s://%s/admin/api/oauth/callback", scheme, r.Host) } // LoginHandler 处理登录请求,重定向到 OAuth 授权页面