Skip to content

Commit

Permalink
make obtain_token a template method for greater compatibility. Remove…
Browse files Browse the repository at this point in the history
…s Zoom implementation, that should go to the docs
  • Loading branch information
willi-mueller committed May 24, 2024
1 parent 5f4b8ec commit 4dbf692
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions dlt/sources/helpers/rest_client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4dbf692

Please sign in to comment.