Skip to content

fix(auth): refresh URL-derived self-signed JWTs on 401 across HTTP transports - #19282

Open
parthea wants to merge 1 commit into
fix/auth-sa-url-jwt-audiencefrom
fix/auth-sa-url-jwt-401-retry
Open

parthea wants to merge 1 commit into
fix/auth-sa-url-jwt-audiencefrom
fix/auth-sa-url-jwt-401-retry

Conversation

@parthea

@parthea parthea commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add keyword-only force_refresh=False to _get_self_signed_jwt_for_audience() and add _refresh_self_signed_jwt_for_url(request, url) on service_account.Credentials to force-refresh the cached per-audience JWT for a given request URL.
  • Update 401 retry handling in google/auth/transport/requests.py (AuthorizedSession), google/auth/transport/urllib3.py (AuthorizedHttp), google/auth/transport/_aiohttp_requests.py (AuthorizedSession), and google/auth/aio/transport/sessions.py (_SyncCredentialsAdapter / AsyncAuthorizedSession) to call _refresh_self_signed_jwt_for_url() when applicable instead of credentials.refresh(), ensuring retries mint a fresh per-audience JWT without raising RefreshError or reusing a cached token.

Stacked on #19280.

@parthea
parthea requested review from a team as code owners November 30, 2026 21:49

@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 implements a mechanism to refresh URL-derived self-signed JWTs upon receiving a 401 Unauthorized response across various transport layers, including aiohttp, requests, and urllib3. The feedback highlights critical NameError bugs in requests.py and urllib3.py due to missing imports of service_account. To fix these errors and prevent circular dependencies, it is highly recommended to use duck typing with getattr to check for the _refresh_self_signed_jwt_for_url method across all transport adapters instead of using explicit isinstance checks.

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.

1 participant