Skip to content

fix(auth): support modern async token responses - #18554

Open
dhairyajangir wants to merge 2 commits into
googleapis:mainfrom
dhairyajangir:fix/auth-async-token-response-compat
Open

dhairyajangir wants to merge 2 commits into
googleapis:mainfrom
dhairyajangir:fix/auth-async-token-response-compat

Conversation

@dhairyajangir

Copy link
Copy Markdown

Using google.auth.aio.transport.aiohttp.Request for an async token grant currently raises TypeError because the token helper awaits the response's streaming content() generator and expects the legacy status attribute. Read modern responses through read() and status_code, while retaining the legacy content()/status path 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):

  • Before the fix, the selected regression tests produced 7 failures for modern responses and 7 passes for legacy responses.
  • 186 async OAuth and relevant modern/legacy transport tests pass on the current base.
  • Final full package unit suite: 2,147 passed, 7 skipped. Aggregate coverage is 97%; every changed executable line is covered.
  • Package-wide Ruff import/format checks (pinned Ruff 0.14.14), flake8, and package metadata/RST checks pass.

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

The existing issue predates this patch. Helper docstrings now describe both response interfaces. Compared with unmodified base 3799568 in the same environment, statement coverage increased from 97.2398% to 97.2410%, and branch coverage increased from 95.8998% to 95.9613%.

Fixes #17139 🦕

@dhairyajangir
dhairyajangir requested review from a team as code owners October 2, 2026 18:52
@google-cla

google-cla Bot commented Oct 2, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth: Align async token endpoint request helper with google.auth.aio.transport spec

1 participant