Skip to content

Commit b1d5d05

Browse files
committed
properly handle case where no access key can be found in response
1 parent 4e6b9f2 commit b1d5d05

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,14 @@ def _make_handled_request(self) -> Any:
218218
headers=self.build_refresh_request_headers(),
219219
)
220220
response_json = response.json()
221-
# extract the access token and add to secrets to avoid logging the raw value
222-
access_key = self._extract_access_token(response_json)
223-
if access_key:
224-
add_to_secrets(access_key)
221+
try:
222+
# extract the access token and add to secrets to avoid logging the raw value
223+
access_key = self._extract_access_token(response_json)
224+
if access_key:
225+
add_to_secrets(access_key)
226+
except ResponseKeysMaxRecurtionReached as e:
227+
## Could not find the access token in the response, so do nothing
228+
pass
225229
# log the response even if the request failed for troubleshooting purposes
226230
self._log_response(response)
227231
response.raise_for_status()
@@ -245,9 +249,7 @@ def _ensure_access_token_in_response(self, response_data: Mapping[str, Any]) ->
245249
246250
This method attempts to extract the access token from the provided response data.
247251
If the access token is not found, it raises an exception indicating that the token
248-
refresh API response was missing the access token. If the access token is found,
249-
it adds the token to the list of secrets to ensure it is replaced before logging
250-
the response.
252+
refresh API response was missing the access token.
251253
252254
Args:
253255
response_data (Mapping[str, Any]): The response data from which to extract the access token.
@@ -262,9 +264,6 @@ def _ensure_access_token_in_response(self, response_data: Mapping[str, Any]) ->
262264
raise Exception(
263265
f"Token refresh API response was missing access token {self.get_access_token_name()}"
264266
)
265-
# Add the access token to the list of secrets so it is replaced before logging the response
266-
# An argument could be made to remove the prevous access key from the list of secrets, but unmasking values seems like a security incident waiting to happen...
267-
add_to_secrets(access_key)
268267
except ResponseKeysMaxRecurtionReached as e:
269268
raise e
270269

0 commit comments

Comments
 (0)