Repository navigation
Conversation
There was a problem hiding this comment.
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.
| auth_request, | ||
| url, | ||
| ) | ||
| is True |
There was a problem hiding this comment.
nit: is the is True needed here?
| await self._refresh_shared() | ||
|
|
||
| async def _refresh_self_signed_jwt_for_url(self, url): | ||
| """Refreshes a URL-derived self-signed JWT if supported by wrapped credentials.""" |
There was a problem hiding this comment.
nit: doc string explaining arguments and return types (like in service_accounts) would be helpful here
|
|
||
| unauthorized = make_response(status=http_client.UNAUTHORIZED) | ||
| ok_response = make_response(status=http_client.OK) | ||
| adapter = AdapterStub([unauthorized, ok_response]) |
There was a problem hiding this comment.
It looks like this test hits 401, and then recovers. It could be helpful to have a test that continuously hits 401, to make sure it is surfaced properly
Summary
force_refresh=Falseto_get_self_signed_jwt_for_audience()and add_refresh_self_signed_jwt_for_url(request, url)onservice_account.Credentialsto force-refresh the cached per-audience JWT for a given request URL.401retry handling ingoogle/auth/transport/requests.py(AuthorizedSession),google/auth/transport/urllib3.py(AuthorizedHttp),google/auth/transport/_aiohttp_requests.py(AuthorizedSession), andgoogle/auth/aio/transport/sessions.py(_SyncCredentialsAdapter/AsyncAuthorizedSession) to call_refresh_self_signed_jwt_for_url()when applicable instead ofcredentials.refresh(), ensuring retries mint a fresh per-audience JWT without raisingRefreshErroror reusing a cached token.Stacked on #19280.