From 4dbf692c8bf43c5c3b9d400f86fa4dbca0e29da5 Mon Sep 17 00:00:00 2001 From: Willi Date: Fri, 24 May 2024 23:01:17 +0530 Subject: [PATCH] make obtain_token a template method for greater compatibility. Removes Zoom implementation, that should go to the docs --- dlt/sources/helpers/rest_client/auth.py | 35 +++++++++---------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/dlt/sources/helpers/rest_client/auth.py b/dlt/sources/helpers/rest_client/auth.py index 5a7efc4a96..562792d11c 100644 --- a/dlt/sources/helpers/rest_client/auth.py +++ b/dlt/sources/helpers/rest_client/auth.py @@ -175,34 +175,25 @@ def __call__(self, request: PreparedRequest) -> PreparedRequest: def is_token_expired(self) -> bool: return pendulum.now() >= self.token_expiry - @abstractmethod - def build_access_token_request(self) -> Dict[str, Any]: - pass - def obtain_token(self) -> None: response = requests.post(**self.build_access_token_request()) response.raise_for_status() - self.access_token = response.json()["access_token"] - expires_in = response.json().get("expires_in", self.default_token_expiration) - self.token_expiry = pendulum.now().add(seconds=expires_in) + response_json = response.json() + self.access_token = self.parse_access_token(response_json) + expires_in_seconds = self.parse_expiration_in_seconds(response_json) + self.token_expiry = pendulum.now().add(seconds=expires_in_seconds) - -class OAuth2Zoom(OAuth2ImplicitFlow): + @abstractmethod def build_access_token_request(self) -> Dict[str, Any]: - """ - This b64-encoded access token request is specific to Zoom. - Many other APIs implement OAuth2 differently - """ - authentication: str = b64encode(f"{self.client_id}:{self.client_secret}".encode()).decode() + pass - return { - "url": self.access_token_url, - "headers": { - "Authorization": f"Basic {authentication}", - "Content-Type": "application/x-www-form-urlencoded", - }, - "data": self.access_token_request_data, - } + @abstractmethod + def parse_expiration_in_seconds(self, response_json: Any) -> int: + pass + + @abstractmethod + def parse_access_token(self, response_json: Any) -> TSecretStrValue: + pass @configspec