googleapis / google-auth-library-python

Google Auth Python Library
https://googleapis.dev/python/google-auth/latest/
Apache License 2.0
752 stars 301 forks source link

The async `AuthorizedSession` doesn't support customized `ClientSession` parameters #1530

Closed hongyiweiwu01 closed 3 weeks ago

hongyiweiwu01 commented 1 month ago

AuthorizedSession takes keyword arguments that are passed down to the ClientSession, so when we make requests using the session that it yields, these arguments are effective. However, AuthorizedSession also does token fresh in its request method, where it manually creates a ClientSession which doesn't include these keyword arguments.

In my scenario, we have to run some logic under a VPN, so I need to pass trust_env into every aiohttp Session, cause otherwise the request would just hang and eventually time out. Because of this I cannot really use AuthorizedSession as it just always times out at the token refresh step.

Environment details

Steps to reproduce

credentials, _ = default_async()
async with AuthorizedSession(trust_env=False) as session:
   await session.request(...)

The code is stuck at the session.request step until it times out if a proxy is used.

Possible solutions

We can just pass the kwargs accepted in the AuthorizedSession constructor into the ClientSession constructor here