Skip to content

Commit

Permalink
Use oauth_api_connector in Zoom connector
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau committed Nov 15, 2023
1 parent 3657b29 commit 39ad845
Showing 1 changed file with 8 additions and 50 deletions.
58 changes: 8 additions & 50 deletions parsons/zoom/zoom.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from parsons.utilities import check_env
from parsons.utilities.api_connector import APIConnector
from parsons.utilities.oauth_api_connector import OAuth2APIConnector
from parsons import Table
import logging
import jwt
import datetime
import uuid

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -32,55 +30,15 @@ def __init__(self, account_id=None, client_id=None, client_secret=None):
self.client_id = check_env.check("ZOOM_CLIENT_ID", client_id)
self.__client_secret = check_env.check("ZOOM_CLIENT_SECRET", client_secret)

self.client = APIConnector(uri=ZOOM_URI)

access_token = self.__generate_access_token()

self.client.headers = {
"Authorization": f"Bearer {access_token}",
"Content-type": "application/json",
}

def __generate_access_token(self) -> str:
"""
Uses Zoom's OAuth callback URL to generate an access token to query the Zoom API
`Returns`:
String representation of access token
"""

temp_client = APIConnector(
uri=ZOOM_URI, auth=(self.client_id, self.__client_secret)
self.client = OAuth2APIConnector(
uri=ZOOM_URI,
client_id=self.client_id,
client_secret=self.__client_secret,
token_url=ZOOM_AUTH_CALLBACK,
auto_refresh_url=ZOOM_AUTH_CALLBACK,
authorization_kwargs={"account_id": self.account_id},
)

resp = temp_client.post_request(
ZOOM_AUTH_CALLBACK,
data={
"grant_type": "account_credentials",
"account_id": self.account_id,
},
)

return resp["access_token"]

def __refresh_header_token(self):
"""
NOTE: This function is deprecated as Zoom's API moves to an OAuth strategy on 9/1
Generate a token that is valid for 30 seconds and update header. Full documentation
on JWT generation using Zoom API: https://marketplace.zoom.us/docs/guides/auth/jwt
"""

payload = {
"iss": self.api_key,
"exp": int(datetime.datetime.now().timestamp() + 30),
}
token = jwt.encode(payload, self.api_secret, algorithm="HS256")
self.client.headers = {
"authorization": f"Bearer {token}",
"content-type": "application/json",
}

def _get_request(self, endpoint, data_key, params=None, **kwargs):
"""
TODO: Consider increasing default page size.
Expand Down

0 comments on commit 39ad845

Please sign in to comment.