|
7 | 7 |
|
8 | 8 | import time
|
9 | 9 |
|
10 |
| -import jwt |
11 | 10 | import requests
|
12 | 11 | from pytz import utc
|
13 | 12 | from requests import Session
|
@@ -172,20 +171,16 @@ class ZoomClient:
|
172 | 171 | 'webinar': WebinarComponent
|
173 | 172 | }
|
174 | 173 |
|
175 |
| - def __init__(self, api_key, api_secret, account_id, client_id, client_secret, timeout=15): |
| 174 | + def __init__(self, account_id, client_id, client_secret, timeout=15): |
176 | 175 | """Create a new Zoom client.
|
177 | 176 |
|
178 |
| - :param api_key: the Zoom JWT API key |
179 |
| - :param api_secret: the Zoom JWT API Secret |
180 | 177 | :param account_id: the Zoom Server OAuth Account ID
|
181 | 178 | :param client_id: the Zoom Server OAuth Client ID
|
182 | 179 | :param client_secret: the Zoom Server OAuth Client Secret
|
183 | 180 | :param timeout: the time out to use for API requests
|
184 | 181 | """
|
185 | 182 | # Setup the config details
|
186 | 183 | config = {
|
187 |
| - 'api_key': api_key, |
188 |
| - 'api_secret': api_secret, |
189 | 184 | 'account_id': account_id,
|
190 | 185 | 'client_id': client_id,
|
191 | 186 | 'client_secret': client_secret,
|
@@ -217,8 +212,6 @@ class ZoomIndicoClient:
|
217 | 212 | def __init__(self):
|
218 | 213 | from indico_vc_zoom.plugin import ZoomPlugin
|
219 | 214 | self.client = ZoomClient(
|
220 |
| - ZoomPlugin.settings.get('api_key'), |
221 |
| - ZoomPlugin.settings.get('api_secret'), |
222 | 215 | ZoomPlugin.settings.get('account_id'),
|
223 | 216 | ZoomPlugin.settings.get('client_id'),
|
224 | 217 | ZoomPlugin.settings.get('client_secret'),
|
@@ -262,36 +255,31 @@ def get_zoom_token(config, *, force=False):
|
262 | 255 | client_id = config['client_id']
|
263 | 256 | client_secret = config['client_secret']
|
264 | 257 |
|
265 |
| - if account_id and client_id and client_secret: |
266 |
| - ZoomPlugin.logger.debug(f'Using Server-to-Server-OAuth ({force=})') |
267 |
| - hash_key = '-'.join((account_id, client_id, client_secret)) |
268 |
| - cache_key = f'token-{crc32(hash_key)}' |
269 |
| - if not force and (token_data := token_cache.get(cache_key)): |
270 |
| - expires_in = int(token_data['expires_at'] - time.time()) |
271 |
| - ZoomPlugin.logger.debug('Using token from cache (%s, %ds remaining)', cache_key, expires_in) |
272 |
| - return token_data['access_token'], token_data['expires_at'] |
273 |
| - try: |
274 |
| - resp = requests.post( |
275 |
| - 'https://zoom.us/oauth/token', |
276 |
| - params={'grant_type': 'account_credentials', 'account_id': account_id}, |
277 |
| - auth=(client_id, client_secret) |
278 |
| - ) |
279 |
| - resp.raise_for_status() |
280 |
| - except HTTPError as exc: |
281 |
| - ZoomPlugin.logger.error('Could not get zoom token: %s', exc.response.text if exc.response else exc) |
282 |
| - raise Exception('Could not get zoom token; please contact an admin if this problem persists.') |
283 |
| - token_data = resp.json() |
284 |
| - assert 'access_token' in token_data |
285 |
| - ZoomPlugin.logger.debug('Got new token from Zoom (expires_in=%s, scope=%s)', token_data['expires_in'], |
286 |
| - token_data['scope']) |
287 |
| - expires_at = int(time.time() + token_data['expires_in']) |
288 |
| - token_data.setdefault('expires_at', expires_at) # zoom doesn't include this. wtf. |
289 |
| - token_cache.set(cache_key, token_data, token_data['expires_in']) |
290 |
| - return token_data['access_token'], token_data['expires_at'] |
291 |
| - elif config['api_key'] and config['api_secret']: |
292 |
| - ZoomPlugin.logger.warning('Using JWT (deprecated)') |
293 |
| - header = {'alg': 'HS256', 'typ': 'JWT'} |
294 |
| - payload = {'iss': config['api_key'], 'exp': int(time.time() + 3600)} |
295 |
| - return jwt.encode(payload, config['api_secret'], algorithm='HS256', headers=header), None |
296 |
| - else: |
| 258 | + if not (account_id and client_id and client_secret): |
297 | 259 | raise Exception('Zoom authentication not configured')
|
| 260 | + |
| 261 | + ZoomPlugin.logger.debug(f'Using Server-to-Server-OAuth ({force=})') |
| 262 | + hash_key = '-'.join((account_id, client_id, client_secret)) |
| 263 | + cache_key = f'token-{crc32(hash_key)}' |
| 264 | + if not force and (token_data := token_cache.get(cache_key)): |
| 265 | + expires_in = int(token_data['expires_at'] - time.time()) |
| 266 | + ZoomPlugin.logger.debug('Using token from cache (%s, %ds remaining)', cache_key, expires_in) |
| 267 | + return token_data['access_token'], token_data['expires_at'] |
| 268 | + try: |
| 269 | + resp = requests.post( |
| 270 | + 'https://zoom.us/oauth/token', |
| 271 | + params={'grant_type': 'account_credentials', 'account_id': account_id}, |
| 272 | + auth=(client_id, client_secret) |
| 273 | + ) |
| 274 | + resp.raise_for_status() |
| 275 | + except HTTPError as exc: |
| 276 | + ZoomPlugin.logger.error('Could not get zoom token: %s', exc.response.text if exc.response else exc) |
| 277 | + raise Exception('Could not get zoom token; please contact an admin if this problem persists.') |
| 278 | + token_data = resp.json() |
| 279 | + assert 'access_token' in token_data |
| 280 | + ZoomPlugin.logger.debug('Got new token from Zoom (expires_in=%s, scope=%s)', token_data['expires_in'], |
| 281 | + token_data['scope']) |
| 282 | + expires_at = int(time.time() + token_data['expires_in']) |
| 283 | + token_data.setdefault('expires_at', expires_at) # zoom doesn't include this. wtf. |
| 284 | + token_cache.set(cache_key, token_data, token_data['expires_in']) |
| 285 | + return token_data['access_token'], token_data['expires_at'] |
0 commit comments