Open
Description
Component
SessionTokenProvider
Relevant information
Currently, the SessionTokenProvider used in the SessionTokenAuthenticator only supports reading the session token from JSON/XML. This limits compatibility with older / legacy APIs which sometimes return the session token in the body as text/plain.
e.g. see slack thread in Community Slack channel.
Proposed solution
Provide a dummy TextDecoder class which can be used in token refresh method 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
Metadata
Metadata
Assignees
Labels
No labels