Skip to content

Commit eaf6dd7

Browse files
committed
bug fixes
1 parent 64027a4 commit eaf6dd7

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

pyatlan/client/aio/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,17 @@ class AsyncAtlanClient(AtlanClient):
132132
_async_user_cache: Optional[AsyncUserCache] = PrivateAttr(default=None)
133133

134134
def __init__(self, **kwargs):
135+
# Initialize sync client (handles all validation, env vars, etc.)
135136
super().__init__(**kwargs)
136137

137-
if self.oauth_client_id and self.oauth_client_secret:
138+
if self.oauth_client_id and self.oauth_client_secret and self.api_key is None:
139+
LOGGER.debug(
140+
"API Key not provided. Using Async OAuth flow for authentication"
141+
)
138142
from pyatlan.client.aio.oauth import AsyncOAuthTokenManager
139143

140144
if self._oauth_token_manager:
145+
LOGGER.debug("Sync oauth flow open. Closing it for Async oauth flow")
141146
self._oauth_token_manager.close()
142147
self._oauth_token_manager = None
143148

@@ -147,6 +152,7 @@ def __init__(self, **kwargs):
147152
client_secret=self.oauth_client_secret,
148153
)
149154

155+
# Build proxy/SSL configuration (reuse from sync client)
150156
transport_kwargs = self._build_transport_proxy_config(kwargs)
151157

152158
# Create async session with custom transport that supports retry and proxy
@@ -707,10 +713,6 @@ async def _handle_error_response(
707713
and response.status_code
708714
== ErrorCode.AUTHENTICATION_PASSTHROUGH.http_error_code
709715
):
710-
"""
711-
Async version of token refresh and retry logic.
712-
Handles token refresh and retries the API request upon a 401 Unauthorized response.
713-
"""
714716
try:
715717
LOGGER.debug("Starting async 401 automatic token refresh.")
716718
return await self._handle_401_token_refresh(
@@ -761,6 +763,10 @@ async def _handle_401_token_refresh(
761763
download_file_path=None,
762764
text_response=False,
763765
):
766+
"""
767+
Async version of token refresh and retry logic.
768+
Handles token refresh and retries the API request upon a 401 Unauthorized response.
769+
"""
764770
if self._async_oauth_token_manager:
765771
await self._async_oauth_token_manager.invalidate_token()
766772
token = await self._async_oauth_token_manager.get_token()

pyatlan/client/aio/oauth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ async def get_token(self) -> str:
4242

4343
data = response.json()
4444
access_token = data.get("accessToken") or data.get("access_token")
45+
46+
if not access_token:
47+
raise ValueError(
48+
f"OAuth token response missing 'accessToken' field. "
49+
f"Response keys: {list(data.keys())}"
50+
)
51+
4552
expires_in = data.get("expiresIn") or data.get("expires_in", 600)
4653

4754
self._token = OAuth2Token(

pyatlan/client/atlan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Config:
176176
def __init__(self, **data):
177177
super().__init__(**data)
178178

179-
if self.oauth_client_id and self.oauth_client_secret:
179+
if self.oauth_client_id and self.oauth_client_secret and self.api_key is None:
180180
from pyatlan.client.oauth import OAuthTokenManager
181181

182182
self._oauth_token_manager = OAuthTokenManager(

pyatlan/client/oauth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def get_token(self) -> str:
4242

4343
data = response.json()
4444
access_token = data.get("accessToken") or data.get("access_token")
45+
46+
if not access_token:
47+
raise ValueError(
48+
f"OAuth token response missing 'accessToken' field. "
49+
f"Response keys: {list(data.keys())}"
50+
)
51+
4552
expires_in = data.get("expiresIn") or data.get("expires_in", 600)
4653

4754
self._token = OAuth2Token(

0 commit comments

Comments
 (0)