mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
feat(auth): 支持自定义OAuth回调地址配置
- 在 docker-compose.yml 中新增 OAUTH_REDIRECT_URI 环境变量配置 - 修改 getCallbackURL 方法,优先使用环境变量指定的回调地址 - 保留原有的自动获取回调地址逻辑作为备选方案 - 增加配置灵活性,方便在不同部署环境中自定义回调地址
This commit is contained in:
parent
a4067a6c66
commit
512ec6707d
@ -10,4 +10,7 @@ services:
|
|||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
- OAUTH_CLIENT_ID=your_client_id
|
- OAUTH_CLIENT_ID=your_client_id
|
||||||
- OAUTH_CLIENT_SECRET=your_client_secret
|
- OAUTH_CLIENT_SECRET=your_client_secret
|
||||||
|
#填写公网访问的地址, 需要跟CZL Connect保持一致.
|
||||||
|
#选填, 不填为自动获取
|
||||||
|
- OAUTH_REDIRECT_URI=https://localhost:3336/admin/api/oauth/callback
|
||||||
restart: always
|
restart: always
|
@ -150,12 +150,16 @@ func (h *ProxyHandler) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
|
|
||||||
// getCallbackURL 从请求中获取回调地址
|
// getCallbackURL 从请求中获取回调地址
|
||||||
func getCallbackURL(r *http.Request) string {
|
func getCallbackURL(r *http.Request) string {
|
||||||
|
if os.Getenv("OAUTH_REDIRECT_URI") != "" {
|
||||||
|
return os.Getenv("OAUTH_REDIRECT_URI")
|
||||||
|
} else {
|
||||||
scheme := "http"
|
scheme := "http"
|
||||||
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||||
scheme = "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 授权页面
|
// LoginHandler 处理登录请求,重定向到 OAuth 授权页面
|
||||||
func (h *ProxyHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *ProxyHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user