google-adk-extras 0.2.6__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_adk_extras/__init__.py +3 -3
- google_adk_extras/adk_builder.py +15 -292
- google_adk_extras/artifacts/local_folder_artifact_service.py +0 -2
- google_adk_extras/artifacts/mongo_artifact_service.py +0 -1
- google_adk_extras/artifacts/s3_artifact_service.py +0 -1
- google_adk_extras/artifacts/sql_artifact_service.py +0 -1
- google_adk_extras/auth/__init__.py +10 -0
- google_adk_extras/auth/attach.py +227 -0
- google_adk_extras/auth/config.py +45 -0
- google_adk_extras/auth/jwt_utils.py +36 -0
- google_adk_extras/auth/sql_store.py +183 -0
- google_adk_extras/custom_agent_loader.py +1 -1
- google_adk_extras/enhanced_adk_web_server.py +0 -2
- google_adk_extras/enhanced_fastapi.py +6 -1
- google_adk_extras/memory/mongo_memory_service.py +0 -1
- google_adk_extras/memory/sql_memory_service.py +1 -1
- google_adk_extras/memory/yaml_file_memory_service.py +1 -3
- google_adk_extras/sessions/mongo_session_service.py +0 -1
- google_adk_extras/sessions/redis_session_service.py +1 -1
- google_adk_extras/sessions/yaml_file_session_service.py +0 -2
- google_adk_extras/streaming/streaming_controller.py +2 -2
- {google_adk_extras-0.2.6.dist-info → google_adk_extras-0.3.0.dist-info}/METADATA +84 -34
- google_adk_extras-0.3.0.dist-info/RECORD +37 -0
- google_adk_extras/credentials/__init__.py +0 -34
- google_adk_extras/credentials/github_oauth2_credential_service.py +0 -213
- google_adk_extras/credentials/google_oauth2_credential_service.py +0 -216
- google_adk_extras/credentials/http_basic_auth_credential_service.py +0 -388
- google_adk_extras/credentials/jwt_credential_service.py +0 -345
- google_adk_extras/credentials/microsoft_oauth2_credential_service.py +0 -250
- google_adk_extras/credentials/x_oauth2_credential_service.py +0 -240
- google_adk_extras-0.2.6.dist-info/RECORD +0 -39
- {google_adk_extras-0.2.6.dist-info → google_adk_extras-0.3.0.dist-info}/WHEEL +0 -0
- {google_adk_extras-0.2.6.dist-info → google_adk_extras-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {google_adk_extras-0.2.6.dist-info → google_adk_extras-0.3.0.dist-info}/top_level.txt +0 -0
@@ -1,240 +0,0 @@
|
|
1
|
-
"""X (Twitter) OAuth2 credential service implementation."""
|
2
|
-
|
3
|
-
from typing import Optional, List
|
4
|
-
import logging
|
5
|
-
|
6
|
-
from google.adk.auth.credential_service.session_state_credential_service import SessionStateCredentialService
|
7
|
-
from google.adk.auth.credential_service.base_credential_service import CallbackContext
|
8
|
-
from google.adk.auth import AuthConfig, AuthCredential, AuthCredentialTypes
|
9
|
-
from google.adk.auth.auth_credential import OAuth2Auth
|
10
|
-
from fastapi.openapi.models import OAuth2
|
11
|
-
from fastapi.openapi.models import OAuthFlowAuthorizationCode, OAuthFlows
|
12
|
-
|
13
|
-
from .base_custom_credential_service import BaseCustomCredentialService
|
14
|
-
|
15
|
-
logger = logging.getLogger(__name__)
|
16
|
-
|
17
|
-
|
18
|
-
class XOAuth2CredentialService(BaseCustomCredentialService):
|
19
|
-
"""X (Twitter) OAuth2 credential service for handling X API authentication flows.
|
20
|
-
|
21
|
-
This service provides pre-configured OAuth2 flows for X API v2 including
|
22
|
-
reading tweets, posting content, and managing user data.
|
23
|
-
|
24
|
-
Args:
|
25
|
-
client_id: The X OAuth2 client ID from X Developer Portal.
|
26
|
-
client_secret: The X OAuth2 client secret from X Developer Portal.
|
27
|
-
scopes: List of OAuth2 scopes to request. Common scopes include:
|
28
|
-
- "tweet.read" - Read tweets
|
29
|
-
- "tweet.write" - Write tweets
|
30
|
-
- "tweet.moderate.write" - Moderate tweets
|
31
|
-
- "users.read" - Read user information
|
32
|
-
- "follows.read" - Read follows information
|
33
|
-
- "follows.write" - Manage follows
|
34
|
-
- "offline.access" - Maintain access when user is offline
|
35
|
-
- "space.read" - Read Spaces information
|
36
|
-
- "mute.read" - Read muted accounts
|
37
|
-
- "mute.write" - Manage muted accounts
|
38
|
-
- "like.read" - Read likes information
|
39
|
-
- "like.write" - Manage likes
|
40
|
-
- "list.read" - Read list information
|
41
|
-
- "list.write" - Manage lists
|
42
|
-
- "block.read" - Read blocked accounts
|
43
|
-
- "block.write" - Manage blocked accounts
|
44
|
-
use_session_state: If True, stores credentials in session state. If False,
|
45
|
-
uses in-memory storage. Default is True for persistence.
|
46
|
-
|
47
|
-
Example:
|
48
|
-
```python
|
49
|
-
credential_service = XOAuth2CredentialService(
|
50
|
-
client_id="your-x-client-id",
|
51
|
-
client_secret="your-x-client-secret",
|
52
|
-
scopes=["tweet.read", "tweet.write", "users.read", "offline.access"]
|
53
|
-
)
|
54
|
-
await credential_service.initialize()
|
55
|
-
|
56
|
-
# Use with Runner
|
57
|
-
runner = Runner(
|
58
|
-
agent=agent,
|
59
|
-
session_service=session_service,
|
60
|
-
credential_service=credential_service,
|
61
|
-
app_name="my_app"
|
62
|
-
)
|
63
|
-
```
|
64
|
-
"""
|
65
|
-
|
66
|
-
# X OAuth2 endpoints
|
67
|
-
X_AUTH_URL = "https://twitter.com/i/oauth2/authorize"
|
68
|
-
X_TOKEN_URL = "https://api.twitter.com/2/oauth2/token"
|
69
|
-
|
70
|
-
# Common X OAuth2 scopes
|
71
|
-
COMMON_SCOPES = {
|
72
|
-
# Tweet scopes
|
73
|
-
"tweet.read": "Read tweets",
|
74
|
-
"tweet.write": "Write tweets",
|
75
|
-
"tweet.moderate.write": "Hide and unhide replies to your tweets",
|
76
|
-
|
77
|
-
# User scopes
|
78
|
-
"users.read": "Read user profile information",
|
79
|
-
|
80
|
-
# Follows scopes
|
81
|
-
"follows.read": "Read who a user is following or who is following a user",
|
82
|
-
"follows.write": "Follow and unfollow other users",
|
83
|
-
|
84
|
-
# Offline access
|
85
|
-
"offline.access": "Maintain access to accounts when users are offline",
|
86
|
-
|
87
|
-
# Space scopes
|
88
|
-
"space.read": "Read Spaces information",
|
89
|
-
|
90
|
-
# Mute scopes
|
91
|
-
"mute.read": "Read muted accounts",
|
92
|
-
"mute.write": "Mute and unmute accounts",
|
93
|
-
|
94
|
-
# Like scopes
|
95
|
-
"like.read": "Read liked tweets",
|
96
|
-
"like.write": "Like and unlike tweets",
|
97
|
-
|
98
|
-
# List scopes
|
99
|
-
"list.read": "Read list information",
|
100
|
-
"list.write": "Create and manage lists",
|
101
|
-
|
102
|
-
# Block scopes
|
103
|
-
"block.read": "Read blocked accounts",
|
104
|
-
"block.write": "Block and unblock accounts",
|
105
|
-
|
106
|
-
# Bookmark scopes
|
107
|
-
"bookmark.read": "Read bookmarked tweets",
|
108
|
-
"bookmark.write": "Bookmark and unbookmark tweets",
|
109
|
-
|
110
|
-
# Direct message scopes
|
111
|
-
"dm.read": "Read direct messages",
|
112
|
-
"dm.write": "Send direct messages",
|
113
|
-
}
|
114
|
-
|
115
|
-
def __init__(
|
116
|
-
self,
|
117
|
-
client_id: str,
|
118
|
-
client_secret: str,
|
119
|
-
scopes: Optional[List[str]] = None,
|
120
|
-
use_session_state: bool = True
|
121
|
-
):
|
122
|
-
"""Initialize the X OAuth2 credential service.
|
123
|
-
|
124
|
-
Args:
|
125
|
-
client_id: X OAuth2 client ID.
|
126
|
-
client_secret: X OAuth2 client secret.
|
127
|
-
scopes: List of OAuth2 scopes to request.
|
128
|
-
use_session_state: Whether to use session state for credential storage.
|
129
|
-
"""
|
130
|
-
super().__init__()
|
131
|
-
self.client_id = client_id
|
132
|
-
self.client_secret = client_secret
|
133
|
-
self.scopes = scopes or ["tweet.read", "users.read", "offline.access"]
|
134
|
-
self.use_session_state = use_session_state
|
135
|
-
|
136
|
-
# Underlying credential service for storage
|
137
|
-
if use_session_state:
|
138
|
-
self._storage_service = SessionStateCredentialService()
|
139
|
-
else:
|
140
|
-
from google.adk.auth.credential_service.in_memory_credential_service import InMemoryCredentialService
|
141
|
-
self._storage_service = InMemoryCredentialService()
|
142
|
-
|
143
|
-
async def _initialize_impl(self) -> None:
|
144
|
-
"""Initialize the X OAuth2 credential service.
|
145
|
-
|
146
|
-
Validates the client credentials and sets up the OAuth2 auth scheme.
|
147
|
-
|
148
|
-
Raises:
|
149
|
-
ValueError: If client_id or client_secret is missing.
|
150
|
-
"""
|
151
|
-
if not self.client_id:
|
152
|
-
raise ValueError("X OAuth2 client_id is required")
|
153
|
-
if not self.client_secret:
|
154
|
-
raise ValueError("X OAuth2 client_secret is required")
|
155
|
-
if not self.scopes:
|
156
|
-
raise ValueError("At least one OAuth2 scope is required")
|
157
|
-
|
158
|
-
# Validate scopes against known X scopes
|
159
|
-
unknown_scopes = set(self.scopes) - set(self.COMMON_SCOPES.keys())
|
160
|
-
if unknown_scopes:
|
161
|
-
logger.warning(f"Unknown X OAuth2 scopes: {unknown_scopes}")
|
162
|
-
|
163
|
-
logger.info(f"Initialized X OAuth2 credential service with scopes: {self.scopes}")
|
164
|
-
|
165
|
-
def create_auth_config(self) -> AuthConfig:
|
166
|
-
"""Create an AuthConfig for X OAuth2 authentication.
|
167
|
-
|
168
|
-
Returns:
|
169
|
-
AuthConfig: Configured auth config for X OAuth2 flow.
|
170
|
-
"""
|
171
|
-
self._check_initialized()
|
172
|
-
|
173
|
-
# Create OAuth2 auth scheme
|
174
|
-
auth_scheme = OAuth2(
|
175
|
-
flows=OAuthFlows(
|
176
|
-
authorizationCode=OAuthFlowAuthorizationCode(
|
177
|
-
authorizationUrl=self.X_AUTH_URL,
|
178
|
-
tokenUrl=self.X_TOKEN_URL,
|
179
|
-
scopes={
|
180
|
-
scope: self.COMMON_SCOPES.get(scope, f"X API scope: {scope}")
|
181
|
-
for scope in self.scopes
|
182
|
-
}
|
183
|
-
)
|
184
|
-
)
|
185
|
-
)
|
186
|
-
|
187
|
-
# Create OAuth2 credential
|
188
|
-
auth_credential = AuthCredential(
|
189
|
-
auth_type=AuthCredentialTypes.OAUTH2,
|
190
|
-
oauth2=OAuth2Auth(
|
191
|
-
client_id=self.client_id,
|
192
|
-
client_secret=self.client_secret
|
193
|
-
)
|
194
|
-
)
|
195
|
-
|
196
|
-
return AuthConfig(
|
197
|
-
auth_scheme=auth_scheme,
|
198
|
-
raw_auth_credential=auth_credential
|
199
|
-
)
|
200
|
-
|
201
|
-
async def load_credential(
|
202
|
-
self,
|
203
|
-
auth_config: AuthConfig,
|
204
|
-
callback_context: CallbackContext,
|
205
|
-
) -> Optional[AuthCredential]:
|
206
|
-
"""Load X OAuth2 credential from storage.
|
207
|
-
|
208
|
-
Args:
|
209
|
-
auth_config: The auth config containing credential key information.
|
210
|
-
callback_context: The current callback context.
|
211
|
-
|
212
|
-
Returns:
|
213
|
-
Optional[AuthCredential]: The stored credential or None if not found.
|
214
|
-
"""
|
215
|
-
self._check_initialized()
|
216
|
-
return await self._storage_service.load_credential(auth_config, callback_context)
|
217
|
-
|
218
|
-
async def save_credential(
|
219
|
-
self,
|
220
|
-
auth_config: AuthConfig,
|
221
|
-
callback_context: CallbackContext,
|
222
|
-
) -> None:
|
223
|
-
"""Save X OAuth2 credential to storage.
|
224
|
-
|
225
|
-
Args:
|
226
|
-
auth_config: The auth config containing the credential to save.
|
227
|
-
callback_context: The current callback context.
|
228
|
-
"""
|
229
|
-
self._check_initialized()
|
230
|
-
await self._storage_service.save_credential(auth_config, callback_context)
|
231
|
-
|
232
|
-
logger.info(f"Saved X OAuth2 credential for user {callback_context._invocation_context.user_id}")
|
233
|
-
|
234
|
-
def get_supported_scopes(self) -> dict:
|
235
|
-
"""Get dictionary of supported X OAuth2 scopes and their descriptions.
|
236
|
-
|
237
|
-
Returns:
|
238
|
-
dict: Mapping of scope names to descriptions.
|
239
|
-
"""
|
240
|
-
return self.COMMON_SCOPES.copy()
|
@@ -1,39 +0,0 @@
|
|
1
|
-
google_adk_extras/__init__.py,sha256=cIaqZH7E__SmojqMjCqOA4FV6S6-k1pH9_mGCfkCfU4,830
|
2
|
-
google_adk_extras/adk_builder.py,sha256=anTpd-UYtPugRSqdYNmWa_uesVjHGEKO2mntkcU-J6g,41179
|
3
|
-
google_adk_extras/custom_agent_loader.py,sha256=6rQyBTAxvuwFPs3QGt8hWYZKsQVpbI4WIy6OS73tsac,6001
|
4
|
-
google_adk_extras/enhanced_adk_web_server.py,sha256=rML_m4Um9QCcnnlHvCOyLGjLHDcyladEunX-x4JX43Q,5414
|
5
|
-
google_adk_extras/enhanced_fastapi.py,sha256=TzIr159B0tnEqj2dXKmV_tJvkA66Fq2I-kL5cz9VGSk,28304
|
6
|
-
google_adk_extras/enhanced_runner.py,sha256=b7O1a9-4S49LduILOEDs6IxjCI4w_E39sc-Hs4y3Rys,1410
|
7
|
-
google_adk_extras/artifacts/__init__.py,sha256=_IsKDgf6wanWR0HXvSpK9SiLa3n5URKLtazkKyH1P-o,931
|
8
|
-
google_adk_extras/artifacts/base_custom_artifact_service.py,sha256=O9rkc250B3yDRYbyDI0EvTrCKvnih5_DQas5OF-hRMY,9721
|
9
|
-
google_adk_extras/artifacts/local_folder_artifact_service.py,sha256=Vb-KYExEcanHy9c1wAjB1n6hVAUw7pg9ZeahWE--Jx8,12533
|
10
|
-
google_adk_extras/artifacts/mongo_artifact_service.py,sha256=z6x7zL4RsPuUYOgv02xkD_c3BNInjTa61ElgsvkZazc,7111
|
11
|
-
google_adk_extras/artifacts/s3_artifact_service.py,sha256=HMOlHzs5Z2DicaTa6O3LJRwzhzPlpBpwftxWtmjwf1I,15669
|
12
|
-
google_adk_extras/artifacts/sql_artifact_service.py,sha256=9wy-UP8rvFng_h66X7mU0y7DRlxI-AcqxRtg6Ph2VDU,11992
|
13
|
-
google_adk_extras/credentials/__init__.py,sha256=sklM_jV5hM_zffABV5TWx-B99bFNrSLP8Ik7Z6mD7Zs,1274
|
14
|
-
google_adk_extras/credentials/base_custom_credential_service.py,sha256=iYHacJAsZmDfpxLOPYx4tQpbtWTbwC75tRp6hlZFoSg,4014
|
15
|
-
google_adk_extras/credentials/github_oauth2_credential_service.py,sha256=bQwVh6uLLH7w_9EtS_BIcEI3VpHS6G93KSzNPB-gsig,8677
|
16
|
-
google_adk_extras/credentials/google_oauth2_credential_service.py,sha256=3zl3bZmzch7gD4FaQinlRzKfS0Z8GRMbn161kIqgwgg,8503
|
17
|
-
google_adk_extras/credentials/http_basic_auth_credential_service.py,sha256=s_t98s1ESnTDMUwg6Z5dvxxZ6aPd5w4Qooz6ZtMNm2I,14305
|
18
|
-
google_adk_extras/credentials/jwt_credential_service.py,sha256=S5JzD2gGrg9YGr8iu4zYsC1B8x6vUijglAVkACOCYOA,12604
|
19
|
-
google_adk_extras/credentials/microsoft_oauth2_credential_service.py,sha256=ST1i3O7LCCOa2RnvTP0mPIFsj5aMtWgfMnCyW2kgyUg,10366
|
20
|
-
google_adk_extras/credentials/x_oauth2_credential_service.py,sha256=zFESyKPjzJJnmdKcU3ZCLZvbHLMPifdKUDYTiN_16vc,8952
|
21
|
-
google_adk_extras/memory/__init__.py,sha256=2FFJXw9CZHctKXmCuc-lrdETeQ5xqdivy3oarHJz5gs,994
|
22
|
-
google_adk_extras/memory/base_custom_memory_service.py,sha256=TRQMaXiRg2LXFwYZnFHoL-yBVtecuX1ownyPBJf6Xww,3613
|
23
|
-
google_adk_extras/memory/mongo_memory_service.py,sha256=M2FGzGaWuEkDILjEpUPx7OOzuek7d1OP9TXzKAeb9jE,6759
|
24
|
-
google_adk_extras/memory/redis_memory_service.py,sha256=P6vYvP8gv6kCH1lRB0SQld3mzS_JVKMUDtKifXDfu38,7400
|
25
|
-
google_adk_extras/memory/sql_memory_service.py,sha256=cmy2sL4bzVi4WWyEeVt7FNhioxSd1OGm7fQKzESvyO8,10766
|
26
|
-
google_adk_extras/memory/yaml_file_memory_service.py,sha256=St1LMYwLE7HnW-hWhckuEKFadlULUPKkqRMwLpOf48I,9941
|
27
|
-
google_adk_extras/sessions/__init__.py,sha256=VgHyPULLzjJD7ShsyABz98rWVND0mOoM6qX74MrTJwA,915
|
28
|
-
google_adk_extras/sessions/base_custom_session_service.py,sha256=npwrSNAtgqN6K7C8e4idiWkFNr_3pcOAiFYpGXu3NnI,8912
|
29
|
-
google_adk_extras/sessions/mongo_session_service.py,sha256=r3jZ3PmDpbZ0veNzXzuAj_fqRWNZL8RO53ESEHrr7uQ,8329
|
30
|
-
google_adk_extras/sessions/redis_session_service.py,sha256=yyfXZozeFWJ2S_kz7zXqz--f_ymE6HMMpT3MhcpFXIE,10434
|
31
|
-
google_adk_extras/sessions/sql_session_service.py,sha256=TaOeEVWnwQ_8nvDZBW7e3qhzR_ecuGsjvZ_kh6Guq8g,14558
|
32
|
-
google_adk_extras/sessions/yaml_file_session_service.py,sha256=SpTh8YHIALcoxzmturhcZ4ReHKQrJI1CxoYiJQ-baRc,11819
|
33
|
-
google_adk_extras/streaming/__init__.py,sha256=rcjmlCJHTlvUiCrx6qNGw5ObCnEtfENkGTvzfEiGL0M,461
|
34
|
-
google_adk_extras/streaming/streaming_controller.py,sha256=Qxg4yqakd3mBPJ9sISe4gO_pvBpYttvSq5SIK4W5ZPQ,10505
|
35
|
-
google_adk_extras-0.2.6.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
36
|
-
google_adk_extras-0.2.6.dist-info/METADATA,sha256=NXbByeiIsdHl2UcZ5F-i22thmm-rFcTr1poTFdVY5cI,10707
|
37
|
-
google_adk_extras-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
38
|
-
google_adk_extras-0.2.6.dist-info/top_level.txt,sha256=DDWgVkz8G8ihPzznxAWyKa2jgJW3F6Fwy__qMddoKTs,18
|
39
|
-
google_adk_extras-0.2.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|