fix(auth): support modern async token responses - #18554
dhairyajangir wants to merge 2 commits into
Conversation
Refactor token endpoint tests to use parameterized requests.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the asynchronous OAuth 2.0 client to support both the new aiohttp transport response interface (which exposes read() and status_code) and the legacy response interface (which exposes content() and status). The _token_endpoint_request_no_throw function was updated to dynamically check for these attributes, and corresponding unit tests were added and parametrized to verify compatibility with both interfaces. There are no review comments, and I have no feedback to provide.
Using
google.auth.aio.transport.aiohttp.Requestfor an async token grant currently raisesTypeErrorbecause the token helper awaits the response's streamingcontent()generator and expects the legacystatusattribute. Read modern responses throughread()andstatus_code, while retaining the legacycontent()/statuspath and its compressed-body decoding.The regression tests exercise successful, text, JSON, error and retry responses through both interfaces, the concrete modern aiohttp response adapter, and legacy gzip decoding. A localhost check using both real request adapters succeeds for plain and gzip token responses after the change; the modern adapter failed for both before it.
Validation (Python 3.12):
The local run covered Python 3.12; the full supported Python/OS matrix and cloud system tests were not run. Existing deprecation and async-mock warnings remain in the package suite.
This change was developed with AI assistance. Reproduction and validation were performed locally without cloud credentials or cloud services.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
The existing issue predates this patch. Helper docstrings now describe both response interfaces. Compared with unmodified base
3799568in the same environment, statement coverage increased from 97.2398% to 97.2410%, and branch coverage increased from 95.8998% to 95.9613%.Fixes #17139 🦕