Skip to content

Commit

Permalink
generalizes OAuth2 implementation. Provides example for Zoom Video co…
Browse files Browse the repository at this point in the history
…mmunications
  • Loading branch information
willi-mueller committed May 21, 2024
1 parent a3b9a8b commit df13fb2
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions dlt/sources/helpers/rest_client/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
from abc import abstractmethod
from base64 import b64encode
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -174,17 +175,26 @@ def __call__(self, request: PreparedRequest) -> PreparedRequest:
def is_token_expired(self) -> bool:
return pendulum.now() >= self.token_expiry

def obtain_token(self) -> None:
authentication: str = b64encode(f"{self.client_id}:{self.client_secret}".encode()).decode()
def build_access_token_request(self) -> dict[str]:
"""
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()

response = requests.post(
url=self.access_token_url,
headers={
return {
"url": self.access_token_url,
"headers": {
"Authorization": f"Basic {authentication}",
"Content-Type": "application/x-www-form-urlencoded",
},
data=self.access_token_request_data,
)
"data": self.access_token_request_data,
}

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)
Expand Down

0 comments on commit df13fb2

Please sign in to comment.