feat: Support refresh access token automatically for rest_api_tool

1. let auth_handler.py to utilize the oauth2 credential fetcher to exchange token
2. restructure tool_auth_handler.py to support refresh token

PiperOrigin-RevId: 770901469
This commit is contained in:
Xiang (Sean) Zhou
2025-06-12 20:07:43 -07:00
committed by Copybara-Service
parent c5b063f1ff
commit 177980106b
4 changed files with 137 additions and 104 deletions
+5 -2
View File
@@ -449,7 +449,7 @@ class TestExchangeAuthToken:
):
"""Test when token exchange is not supported."""
monkeypatch.setattr(
"google.adk.auth.auth_handler.SUPPORT_TOKEN_EXCHANGE", False
"google.adk.auth.oauth2_credential_fetcher.AUTHLIB_AVIALABLE", False
)
handler = AuthHandler(auth_config_with_auth_code)
@@ -537,7 +537,10 @@ class TestExchangeAuthToken:
assert result == oauth2_credentials_with_token
@patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session)
@patch(
"google.adk.auth.oauth2_credential_fetcher.OAuth2Session",
MockOAuth2Session,
)
def test_successful_token_exchange(self, auth_config_with_auth_code):
"""Test a successful token exchange."""
handler = AuthHandler(auth_config_with_auth_code)