Skip to content

Commit 9a1115c

Browse files
seanzhougooglecopybara-github
authored andcommitted
chore: Remove service account support
given it was not correctly supported. PiperOrigin-RevId: 773137317
1 parent 913d771 commit 9a1115c

File tree

11 files changed

+15
-760
lines changed

11 files changed

+15
-760
lines changed

src/google/adk/auth/auth_credential.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,3 @@ class AuthCredential(BaseModelWithConfig):
230230
http: Optional[HttpAuth] = None
231231
service_account: Optional[ServiceAccount] = None
232232
oauth2: Optional[OAuth2Auth] = None
233-
google_oauth2_json: Optional[str] = None

src/google/adk/auth/credential_manager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ def __init__(
7676
self._refresher_registry = CredentialRefresherRegistry()
7777

7878
# Register default exchangers and refreshers
79-
from .exchanger.service_account_credential_exchanger import ServiceAccountCredentialExchanger
80-
81-
self._exchanger_registry.register(
82-
AuthCredentialTypes.SERVICE_ACCOUNT, ServiceAccountCredentialExchanger()
83-
)
79+
# TODO: support service account credential exchanger
8480
from .refresher.oauth2_credential_refresher import OAuth2CredentialRefresher
8581

8682
oauth2_refresher = OAuth2CredentialRefresher()

src/google/adk/auth/exchanger/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"""Credential exchanger module."""
1616

1717
from .base_credential_exchanger import BaseCredentialExchanger
18-
from .service_account_credential_exchanger import ServiceAccountCredentialExchanger
1918

2019
__all__ = [
2120
"BaseCredentialExchanger",
22-
"ServiceAccountCredentialExchanger",
2321
]

src/google/adk/auth/exchanger/service_account_credential_exchanger.py

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/google/adk/auth/refresher/oauth2_credential_refresher.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,12 @@ async def is_refresh_needed(
6060
Returns:
6161
True if the credential needs to be refreshed, False otherwise.
6262
"""
63-
# Handle Google OAuth2 credentials (from service account exchange)
64-
if auth_credential.google_oauth2_json:
65-
try:
66-
google_credential = Credentials.from_authorized_user_info(
67-
json.loads(auth_credential.google_oauth2_json)
68-
)
69-
return google_credential.expired and bool(
70-
google_credential.refresh_token
71-
)
72-
except Exception as e:
73-
logger.warning("Failed to parse Google OAuth2 JSON credential: %s", e)
74-
return False
7563

7664
# Handle regular OAuth2 credentials
77-
elif auth_credential.oauth2 and auth_scheme:
65+
if auth_credential.oauth2:
7866
if not AUTHLIB_AVIALABLE:
7967
return False
8068

81-
if not auth_credential.oauth2:
82-
return False
83-
8469
return OAuth2Token({
8570
"expires_at": auth_credential.oauth2.expires_at,
8671
"expires_in": auth_credential.oauth2.expires_in,
@@ -105,22 +90,9 @@ async def refresh(
10590
The refreshed credential.
10691
10792
"""
108-
# Handle Google OAuth2 credentials (from service account exchange)
109-
if auth_credential.google_oauth2_json:
110-
try:
111-
google_credential = Credentials.from_authorized_user_info(
112-
json.loads(auth_credential.google_oauth2_json)
113-
)
114-
if google_credential.expired and google_credential.refresh_token:
115-
google_credential.refresh(Request())
116-
auth_credential.google_oauth2_json = google_credential.to_json()
117-
logger.info("Successfully refreshed Google OAuth2 JSON credential")
118-
except Exception as e:
119-
# TODO reconsider whether we should raise error when refresh failed.
120-
logger.error("Failed to refresh Google OAuth2 JSON credential: %s", e)
12193

12294
# Handle regular OAuth2 credentials
123-
elif auth_credential.oauth2 and auth_scheme:
95+
if auth_credential.oauth2 and auth_scheme:
12496
if not AUTHLIB_AVIALABLE:
12597
return auth_credential
12698

src/google/adk/tools/mcp_tool/mcp_tool.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ async def _get_headers(
138138
if credential:
139139
if credential.oauth2:
140140
headers = {"Authorization": f"Bearer {credential.oauth2.access_token}"}
141-
elif credential.google_oauth2_json:
142-
google_credential = Credentials.from_authorized_user_info(
143-
json.loads(credential.google_oauth2_json)
144-
)
145-
headers = {"Authorization": f"Bearer {google_credential.token}"}
146141
elif credential.http:
147142
# Handle HTTP authentication schemes
148143
if (
@@ -178,10 +173,9 @@ async def _get_headers(
178173
headers = {"X-API-Key": credential.api_key}
179174
elif credential.service_account:
180175
# Service accounts should be exchanged for access tokens before reaching this point
181-
# If we reach here, we can try to use google_oauth2_json or log a warning
182176
logger.warning(
183-
"Service account credentials should be exchanged for access"
184-
" tokens before MCP session creation"
177+
"Service account credentials should be exchanged before MCP"
178+
" session creation"
185179
)
186180

187181
return headers

src/google/adk/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def _external_exchange_required(self, credential) -> bool:
233233
AuthCredentialTypes.OPEN_ID_CONNECT,
234234
)
235235
and not credential.oauth2.access_token
236-
and not credential.google_oauth2_json
237236
)
238237

239238
async def prepare_auth_credentials(

0 commit comments

Comments
 (0)