go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
43.82k stars 5.38k forks source link

Proxy settings do not take effect on oauth #31496

Open RonsonNamek opened 2 months ago

RonsonNamek commented 2 months ago

Description

I use gitea in docker, and set up oauth2 client with google. when i login with google, it shows account confirm page,

无标题

but after After continue, the page will stay for a few seconds, then redirect to my gitea page and show 500.

error page: image

the gitea log:

2024/06/26 | 08:28:12 ...eb/routing/logger.go:68:func1() [W] router: slow GET /user/oauth2/Google/callback?state=ae3c5578-e834-46af-8213-030808afddcf&code=4%2F0ATx3LY5AXl-AaFvS2-Wd7HZQJG7S9AZj7R9C5_cXxXTf9vz7lEDHYlKpMx1SU30BkJ7sjw&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent for 172.17.0.1:57394, elapsed 3865.0ms @ auth/oauth.go:906(auth.SignInOAuthCallback)
2024/06/26 | 08:11:44 ...rs/web/auth/oauth.go:957:SignInOAuthCallback() [E] UserSignIn: Post "https://oauth2.googleapis.com/token": dial tcp 172.217.160.74:443: i/o timeout

i config proxy in app.ini:

[proxy]
PROXY_ENABLED = true
PROXY_URL     = socks://192.168.25.2:1080
PROXY_HOSTS   = *.gmail.com,*.googleapis.com

[oauth2_client]
REGISTER_EMAIL_CONFIRM = true
ENABLE_AUTO_REGISTRATION = false
USERNAME = nickname
UPDATE_AVATAR = true
ACCOUNT_LINKING = login

when i use commandline in docker containner and try to connect https://oauth2.googleapis.com it also timeout:

curl https://oauth2.googleapis.com

image

but if i use

curl -x socks://192.168.25.2:1080 https://oauth2.googleapis.com

I will receive a response in less than 1 second. image

so it proved my proxy config is ok, but when gitea call https://oauth2.googleapis.com/token, It's not using the proxy I configured

Gitea Version

1.22.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.45.1

Operating System

No response

How are you running Gitea?

docker

Database

PostgreSQL

techknowlogick commented 1 month ago

Hmm.. we use the goth library for oauth handling, so maybe we should pass our http client to the library so it can leverage our settings/configuration