marqetive-lib 0.1.13__py3-none-any.whl → 0.1.14__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.
marqetive/utils/oauth.py CHANGED
@@ -120,6 +120,9 @@ async def refresh_twitter_token(
120
120
  ) -> AuthCredentials:
121
121
  """Refresh Twitter OAuth2 access token.
122
122
 
123
+ Twitter requires HTTP Basic Authentication with client credentials
124
+ in the Authorization header, not in the request body.
125
+
123
126
  Args:
124
127
  credentials: Current credentials with refresh token.
125
128
  client_id: Twitter OAuth client ID.
@@ -144,6 +147,8 @@ async def refresh_twitter_token(
144
147
  ... os.getenv("TWITTER_CLIENT_SECRET")
145
148
  ... )
146
149
  """
150
+ import base64
151
+
147
152
  if not credentials.refresh_token:
148
153
  raise PlatformAuthError(
149
154
  "No refresh token available",
@@ -152,12 +157,42 @@ async def refresh_twitter_token(
152
157
 
153
158
  token_url = "https://api.x.com/2/oauth2/token"
154
159
 
155
- token_data = await refresh_oauth2_token(
156
- refresh_token=credentials.refresh_token,
157
- client_id=client_id,
158
- client_secret=client_secret,
159
- token_url=token_url,
160
- )
160
+ # Twitter requires Basic Auth header for confidential clients
161
+ basic_auth = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()
162
+
163
+ params = {
164
+ "grant_type": "refresh_token",
165
+ "refresh_token": credentials.refresh_token,
166
+ }
167
+
168
+ try:
169
+ async with httpx.AsyncClient() as client:
170
+ response = await client.post(
171
+ token_url,
172
+ data=params,
173
+ headers={
174
+ "Content-Type": "application/x-www-form-urlencoded",
175
+ "Authorization": f"Basic {basic_auth}",
176
+ },
177
+ timeout=30.0,
178
+ )
179
+ response.raise_for_status()
180
+ token_data = response.json()
181
+
182
+ except httpx.HTTPStatusError as e:
183
+ logger.error(f"HTTP error refreshing Twitter token: {e.response.status_code}")
184
+ raise PlatformAuthError(
185
+ f"Failed to refresh token: {_sanitize_response_text(e.response.text)}",
186
+ platform="twitter",
187
+ status_code=e.response.status_code,
188
+ ) from e
189
+
190
+ except httpx.HTTPError as e:
191
+ logger.error(f"Network error refreshing Twitter token: {e}")
192
+ raise PlatformAuthError(
193
+ f"Network error refreshing token: {e}",
194
+ platform="twitter",
195
+ ) from e
161
196
 
162
197
  # Update credentials
163
198
  credentials.access_token = token_data["access_token"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: marqetive-lib
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: Modern Python utilities for web APIs
5
5
  Keywords: api,utilities,web,http,marqetive
6
6
  Requires-Python: >=3.12
@@ -31,9 +31,9 @@ marqetive/utils/__init__.py,sha256=bSrNajbxYBSKQayrPviLz8JeGjplnyK8y_NGDtgb7yQ,9
31
31
  marqetive/utils/file_handlers.py,sha256=4TP5kmWofNTSZmlS683CM1UYP83WvRd_NubMbqtXv-g,12568
32
32
  marqetive/utils/helpers.py,sha256=8-ljhL47SremKcQO2GF8DIHOPODEv1rSioVNuSPCbec,2634
33
33
  marqetive/utils/media.py,sha256=O1rISYdaP3CuuPxso7kqvxWXNfe2jjioNkaBc4cpwkY,14668
34
- marqetive/utils/oauth.py,sha256=1SkYCE6dcyPvcDqbjRFSSBcKTwLJy8u3jAANPdftVmo,13108
34
+ marqetive/utils/oauth.py,sha256=gi5OS_gTit_pG8pyC3I934ayavi_TVnhHwZTwbeoGe4,14364
35
35
  marqetive/utils/retry.py,sha256=lAniJLMNWp9XsHrvU0XBNifpNEjfde4MGfd5hlFTPfA,7636
36
36
  marqetive/utils/token_validator.py,sha256=dNvDeHs2Du5UyMMH2ZOW6ydR7OwOEKA4c9e-rG0f9-0,6698
37
- marqetive_lib-0.1.13.dist-info/METADATA,sha256=1yExpmKMETEBworXCnaoIVuU9UaDH9nJFbEy8DgMqeI,7876
38
- marqetive_lib-0.1.13.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
39
- marqetive_lib-0.1.13.dist-info/RECORD,,
37
+ marqetive_lib-0.1.14.dist-info/METADATA,sha256=GOW1Yf5xAkT3prFFfWRu-4oZEzM1yrPPJxHnOHyBr7o,7876
38
+ marqetive_lib-0.1.14.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
39
+ marqetive_lib-0.1.14.dist-info/RECORD,,