airbytehq / airbytehq/airbyte-python-cdk

[Declarative Source] SessionTokenProvider should support reading session token from text/plain auth response

Đang mở
#404 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
community
Ngôn ngữ chính
Python
Star
26
Fork
53
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
10

Mô tả

## Component
SessionTokenProvider

## Relevant information
Currently, the [SessionTokenProvider](https://github.com/airbytehq/airbyte-python-cdk/blob/969dec1d2f2f22d821b3abcb420c149e0354ed35/airbyte_cdk/sources/declarative/auth/token_provider.py#L32) used in the SessionTokenAuthenticator only supports reading the session token from [JSON/XML](https://github.com/airbytehq/airbyte-python-cdk/blob/969dec1d2f2f22d821b3abcb420c149e0354ed35/airbyte_cdk/sources/declarative/models/declarative_component_schema.py#L2062). This limits compatibility with older / legacy APIs which sometimes return the session token in the body as text/plain.

e.g. see [slack thread](https://airbytehq.slack.com/archives/C027KKE4BCZ/p1741577205250339) in Community Slack channel.

## Proposed solution
Provide a dummy TextDecoder class which can be used in token [refresh method](https://github.com/airbytehq/airbyte-python-cdk/blob/969dec1d2f2f22d821b3abcb420c149e0354ed35/airbyte_cdk/sources/declarative/auth/token_provider.py#L66) to conditional return response.text if decoder isinstance of TextDecoder.

```
class SessionTokenProvider(TokenProvider):
...

def _refresh(self) -> None:
response = self.login_requester.send_request(
log_formatter=lambda response: format_http_message(
response,
"Login request",
"Obtains session token",
None,
is_auxiliary=True,
type="AUTH",
),
)
if response is None:
raise ReadException("Failed to get session token, response got ignored by requester")
session_token = dpath.get(next(self.decoder.decode(response)), self.session_token_path) if not isinstance(self.decoder, TextDecoder) else response.text
if self.expiration_duration is not None:
self._next_expiration_time = ab_datetime_now() + self.expiration_duration
self._token = session_token # type: ignore # Returned decoded response will be Mapping and therefore session_token will be str or None
```

✅ Yes, I want to contribute

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.