From 788a95c13f80f0d16a279fb426d9a2e2b65bd033 Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Mon, 20 Dec 2021 15:59:04 +0200 Subject: [PATCH 1/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- .../batch/KZoomDropFolderEngine.php | 5 +++-- .../batch/processors/zoomProcessor.php | 5 +++-- .../lib/api/KalturaZoomDropFolder.php | 12 +++++++++--- plugins/vendor/zoom/infra/kZoomClient.php | 9 ++++++--- plugins/vendor/zoom/lib/model/kZoomEventHanlder.php | 7 ++++--- .../zoom/lib/model/processors/kZoomProcessor.php | 7 ++++--- .../lib/model/processors/kZoomRecordingProcessor.php | 6 +++--- plugins/vendor/zoom/services/ZoomVendorService.php | 6 +++--- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php index 18d57874296..8e345e42847 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php @@ -83,8 +83,9 @@ protected function initZoomClient(KalturaDropFolder $dropFolder) $refreshToken = isset($dropFolder->refreshToken) ? $dropFolder->refreshToken : null; $clientId = isset($dropFolder->clientId) ? $dropFolder->clientId : null; $clientSecret = isset($dropFolder->clientSecret) ? $dropFolder->clientSecret : null; - $accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null; - return new kZoomClient($dropFolder->baseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken); + $accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null; + $expiresIn = isset($dropFolder->expiresIn) ? $dropFolder->expiresIn : null; + return new kZoomClient($dropFolder->baseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); } protected function getMeetingsInStartTimeOrder() diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php index a76ccf0d145..10665b59c29 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php @@ -32,8 +32,9 @@ public function __construct($zoomBaseUrl, KalturaZoomDropFolder $folder) $refreshToken = isset($folder->refreshToken) ? $folder->refreshToken : null; $clientId = isset($folder->clientId) ? $folder->clientId : null; $clientSecret = isset($folder->clientSecret) ? $folder->clientSecret : null; - $accessToken = isset($folder->accessToken) ? $folder->accessToken : null; - $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken); + $accessToken = isset($folder->accessToken) ? $folder->accessToken : null; + $expiresIn = isset($folder->expiresIn) ? $folder->expiresIn : null; + $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); $this->dropFolder = $folder; } diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php index bad4a4b43a1..88040907d5c 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php @@ -19,8 +19,13 @@ class KalturaZoomDropFolder extends KalturaDropFolder * @readonly */ public $accessToken; - - /** + + /** + * @readonly + */ + public $expiresIn; + + /** * @readonly */ public $clientId; @@ -87,9 +92,10 @@ public function doFromObject($sourceObject, KalturaDetachedResponseProfile $resp $this -> jwtToken = $vendorIntegration -> getJwtToken(); $this -> refreshToken = $vendorIntegration -> getRefreshToken(); $this -> accessToken = $vendorIntegration -> getAccessToken(); + $this -> expiresIn = $vendorIntegration -> getExpiresIn(); $this -> description = $vendorIntegration->getZoomAccountDescription(); $zoomClient = new kZoomClient($this -> baseURL, $this -> jwtToken, $this -> refreshToken, $this -> clientId, - $this -> clientSecret, $this -> accessToken); + $this -> clientSecret, $this -> accessToken, $this -> expiresIn); if ($this -> accessToken && $this -> refreshToken && kCurrentContext ::$ks_partner_id == Partner::BATCH_PARTNER_ID && $vendorIntegration -> getExpiresIn() <= time() + diff --git a/plugins/vendor/zoom/infra/kZoomClient.php b/plugins/vendor/zoom/infra/kZoomClient.php index fc61f141931..94a06fbf852 100644 --- a/plugins/vendor/zoom/infra/kZoomClient.php +++ b/plugins/vendor/zoom/infra/kZoomClient.php @@ -23,6 +23,7 @@ class kZoomClient protected $zoomBaseURL; protected $refreshToken; protected $accessToken; + protected $expiresIn; protected $jwtToken; protected $clientId; protected $clientSecret; @@ -35,11 +36,12 @@ class kZoomClient * @param null $refreshToken * @param null $clientId * @param null $clientSecret - * @param null $accessToken + * @param null $accessToken + * @param null $expiresIn * @throws KalturaAPIException */ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null, $clientId = null, - $clientSecret= null, $accessToken = null) + $clientSecret= null, $accessToken = null, $expiresIn = null) { $this -> zoomBaseURL = $zoomBaseURL; // check if at least one is available, otherwise throw exception @@ -52,6 +54,7 @@ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->accessToken = $accessToken; + $this->expiresIn = $expiresIn; $this->zoomTokensHelper = new kZoomTokens($zoomBaseURL, $clientId, $clientSecret); } @@ -258,7 +261,7 @@ protected function generateContextualUrl($apiPath) $url = $this -> zoomBaseURL . $apiPath . '?'; if ($this->refreshToken) { - if (!$this->accessToken) + if (!$this->accessToken || ($this->expiresIn && $this->expiresIn <= time())) { $this->refreshTokens(); } diff --git a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php index 49c10b1a600..565b95ceaa4 100644 --- a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php +++ b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php @@ -85,7 +85,7 @@ public function processEvent($event) $transcriptProcessor = new kZoomTranscriptProcessor($this->zoomConfiguration[kZoomClient::ZOOM_BASE_URL], $zoomVendorIntegration->getJwtToken(), $zoomVendorIntegration->getRefreshToken(), - null, null, $zoomVendorIntegration->getAccessToken()); + null, null, $zoomVendorIntegration->getAccessToken(),$zoomVendorIntegration->getExpiresIn()); $transcriptProcessor->handleRecordingTranscriptComplete($event); } break; @@ -96,12 +96,13 @@ protected function initZoomClient(ZoomVendorIntegration $zoomVendorIntegration) { $jwtToken = $zoomVendorIntegration->getJwtToken(); $refreshToken = $zoomVendorIntegration->getRefreshToken(); - $accessToken = $zoomVendorIntegration->getAccessToken(); + $accessToken = $zoomVendorIntegration->getAccessToken(); + $expiresIn = $zoomVendorIntegration->getExpiresIn(); $zoomConfiguration = kConf::get(self::CONFIGURATION_PARAM_NAME, self::MAP_NAME); $clientId = $zoomConfiguration['clientId']; $zoomBaseURL = $zoomConfiguration['ZoomBaseUrl']; $clientSecret = $zoomConfiguration['clientSecret']; - return new kZoomClient($zoomBaseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken); + return new kZoomClient($zoomBaseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); } diff --git a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php index fa8fe8f0542..1e0600ff2f1 100644 --- a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php +++ b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php @@ -25,11 +25,12 @@ abstract class kZoomProcessor * @param string $refreshToken * @param string $clientId * @param string $clientSecret - * @param string $accessToken + * @param string $accessToken + * @param string $expiresIn */ - public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken) + public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn) { - $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken); + $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); } /** diff --git a/plugins/vendor/zoom/lib/model/processors/kZoomRecordingProcessor.php b/plugins/vendor/zoom/lib/model/processors/kZoomRecordingProcessor.php index 27ddddc0b87..1fe8ede3908 100644 --- a/plugins/vendor/zoom/lib/model/processors/kZoomRecordingProcessor.php +++ b/plugins/vendor/zoom/lib/model/processors/kZoomRecordingProcessor.php @@ -33,7 +33,7 @@ public function __construct($zoomBaseUrl) $this->zoomBaseUrl = $zoomBaseUrl; $this->zoomIntegration = ZoomHelper::getZoomIntegration(); parent::__construct($zoomBaseUrl, $this->zoomIntegration->getJwtToken(), $this->zoomIntegration->getRefreshToken(), null, null, - $this->zoomIntegration->getAccessToken()); + $this->zoomIntegration->getAccessToken(), $this->zoomIntegration->getExpiresIn()); } /** @@ -88,8 +88,8 @@ public function handleRecordingVideoComplete($event) if (isset($recordingFilesPerTimeSlot[kRecordingFileType::CHAT])) { - $chatFilesProcessor = new kZoomChatFilesProcessor($this->zoomBaseUrl, $this->zoomIntegration->getJwtToken(), - $this->zoomIntegration->getRefreshToken(), null, null, $this->zoomIntegration->getAccessToken()); + $chatFilesProcessor = new kZoomChatFilesProcessor($this->zoomBaseUrl, $this->zoomIntegration->getJwtToken(), $this->zoomIntegration->getRefreshToken(), + null, null, $this->zoomIntegration->getAccessToken(), $this->zoomIntegration->getExpiresIn()); foreach($recordingFilesPerTimeSlot[kRecordingFileType::CHAT] as $recordingFile) { diff --git a/plugins/vendor/zoom/services/ZoomVendorService.php b/plugins/vendor/zoom/services/ZoomVendorService.php index 18c00c25c98..95949800c0d 100644 --- a/plugins/vendor/zoom/services/ZoomVendorService.php +++ b/plugins/vendor/zoom/services/ZoomVendorService.php @@ -103,7 +103,7 @@ public function preOauthValidation() $authCode = $_GET[self::AUTH_CODE]; $tokens = kZoomOauth::requestAccessToken($authCode); $accessToken = $tokens[kZoomOauth::ACCESS_TOKEN]; - $client = new kZoomClient($zoomBaseURL, null, null, null, null, $accessToken ); + $client = new kZoomClient($zoomBaseURL, null, null, null, null, $accessToken, null); $permissions = $client->retrieveTokenZoomUserPermissions(); $user = $client->retrieveTokenZoomUser(); $accountId = $user[ZoomHelper::ACCOUNT_ID]; @@ -184,7 +184,7 @@ public function fetchRegistrationPageAction($tokensData, $iv) $zoomConfiguration = self::getZoomConfiguration(); $tokens = $this->handleEncryptTokens($tokensData, $iv, $zoomConfiguration); $zoomBaseURL = $zoomConfiguration[kZoomClient::ZOOM_BASE_URL]; - $client = new kZoomClient($zoomBaseURL,null,$tokens[kZoomTokens::REFRESH_TOKEN],null,null,$tokens[kZoomTokens::ACCESS_TOKEN]); + $client = new kZoomClient($zoomBaseURL,null,$tokens[kZoomTokens::REFRESH_TOKEN],null,null,$tokens[kZoomTokens::ACCESS_TOKEN], null); $accountId = $this->getAccountId($client->retrieveTokenZoomUser()); $zoomIntegration = ZoomHelper::getZoomIntegrationByAccountId($accountId, true); $partnerId = kCurrentContext::getCurrentPartnerId(); @@ -216,7 +216,7 @@ public function localRegistrationPageAction($jwt) } $zoomConfiguration = self::getZoomConfiguration(); $zoomBaseURL = $zoomConfiguration[kZoomClient::ZOOM_BASE_URL]; - $client = new kZoomClient($zoomBaseURL,$jwt,null,null,null,null); + $client = new kZoomClient($zoomBaseURL,$jwt,null,null,null,null, null); $zoomAccountId = $this->getAccountId($client->retrieveTokenZoomUser()); $zoomIntegration = ZoomHelper::getZoomIntegrationByAccountId($zoomAccountId); if(!$zoomIntegration) From 45701e300c16e873af47d1f234e6affef9f30cda Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Mon, 20 Dec 2021 16:23:22 +0200 Subject: [PATCH 2/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- .../zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php | 4 ++-- .../ZoomDropFolderPlugin/batch/processors/zoomProcessor.php | 4 ++-- .../ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php | 4 ++-- plugins/vendor/zoom/lib/model/kZoomEventHanlder.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php index 8e345e42847..c72ce1e434a 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php @@ -83,8 +83,8 @@ protected function initZoomClient(KalturaDropFolder $dropFolder) $refreshToken = isset($dropFolder->refreshToken) ? $dropFolder->refreshToken : null; $clientId = isset($dropFolder->clientId) ? $dropFolder->clientId : null; $clientSecret = isset($dropFolder->clientSecret) ? $dropFolder->clientSecret : null; - $accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null; - $expiresIn = isset($dropFolder->expiresIn) ? $dropFolder->expiresIn : null; + $accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null; + $expiresIn = isset($dropFolder->expiresIn) ? $dropFolder->expiresIn : null; return new kZoomClient($dropFolder->baseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); } diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php index 10665b59c29..2f7728e8f59 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php @@ -32,8 +32,8 @@ public function __construct($zoomBaseUrl, KalturaZoomDropFolder $folder) $refreshToken = isset($folder->refreshToken) ? $folder->refreshToken : null; $clientId = isset($folder->clientId) ? $folder->clientId : null; $clientSecret = isset($folder->clientSecret) ? $folder->clientSecret : null; - $accessToken = isset($folder->accessToken) ? $folder->accessToken : null; - $expiresIn = isset($folder->expiresIn) ? $folder->expiresIn : null; + $accessToken = isset($folder->accessToken) ? $folder->accessToken : null; + $expiresIn = isset($folder->expiresIn) ? $folder->expiresIn : null; $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); $this->dropFolder = $folder; } diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php index 88040907d5c..740f7095ac6 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php @@ -20,10 +20,10 @@ class KalturaZoomDropFolder extends KalturaDropFolder */ public $accessToken; - /** + /** * @readonly */ - public $expiresIn; + public $expiresIn; /** * @readonly diff --git a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php index 565b95ceaa4..355d1149436 100644 --- a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php +++ b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php @@ -96,8 +96,8 @@ protected function initZoomClient(ZoomVendorIntegration $zoomVendorIntegration) { $jwtToken = $zoomVendorIntegration->getJwtToken(); $refreshToken = $zoomVendorIntegration->getRefreshToken(); - $accessToken = $zoomVendorIntegration->getAccessToken(); - $expiresIn = $zoomVendorIntegration->getExpiresIn(); + $accessToken = $zoomVendorIntegration->getAccessToken(); + $expiresIn = $zoomVendorIntegration->getExpiresIn(); $zoomConfiguration = kConf::get(self::CONFIGURATION_PARAM_NAME, self::MAP_NAME); $clientId = $zoomConfiguration['clientId']; $zoomBaseURL = $zoomConfiguration['ZoomBaseUrl']; From 1239eb3a47587b040a40b8e2154113f52c1316b1 Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Tue, 21 Dec 2021 12:56:17 +0200 Subject: [PATCH 3/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- .../batch/KZoomDropFolderEngine.php | 4 ++-- .../batch/processors/zoomProcessor.php | 4 ++-- .../lib/api/KalturaZoomDropFolder.php | 7 ++++--- plugins/vendor/zoom/infra/kZoomClient.php | 11 ++++++----- plugins/vendor/zoom/lib/model/kZoomEventHanlder.php | 4 ++-- .../zoom/lib/model/processors/kZoomProcessor.php | 6 +++--- plugins/vendor/zoom/services/ZoomVendorService.php | 7 ++++--- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php index c72ce1e434a..b7b1ff98563 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php @@ -84,8 +84,8 @@ protected function initZoomClient(KalturaDropFolder $dropFolder) $clientId = isset($dropFolder->clientId) ? $dropFolder->clientId : null; $clientSecret = isset($dropFolder->clientSecret) ? $dropFolder->clientSecret : null; $accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null; - $expiresIn = isset($dropFolder->expiresIn) ? $dropFolder->expiresIn : null; - return new kZoomClient($dropFolder->baseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); + $accessExpiresIn = isset($dropFolder->accessExpiresIn) ? $dropFolder->accessExpiresIn : null; + return new kZoomClient($dropFolder->baseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn); } protected function getMeetingsInStartTimeOrder() diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php index 2f7728e8f59..b263feed8c4 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/processors/zoomProcessor.php @@ -33,8 +33,8 @@ public function __construct($zoomBaseUrl, KalturaZoomDropFolder $folder) $clientId = isset($folder->clientId) ? $folder->clientId : null; $clientSecret = isset($folder->clientSecret) ? $folder->clientSecret : null; $accessToken = isset($folder->accessToken) ? $folder->accessToken : null; - $expiresIn = isset($folder->expiresIn) ? $folder->expiresIn : null; - $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); + $accessExpiresIn = isset($folder->accessExpiresIn) ? $folder->accessExpiresIn : null; + $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn); $this->dropFolder = $folder; } diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php index 740f7095ac6..5dd9d4d8763 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php @@ -23,7 +23,7 @@ class KalturaZoomDropFolder extends KalturaDropFolder /** * @readonly */ - public $expiresIn; + public $accessExpiresIn; /** * @readonly @@ -92,10 +92,10 @@ public function doFromObject($sourceObject, KalturaDetachedResponseProfile $resp $this -> jwtToken = $vendorIntegration -> getJwtToken(); $this -> refreshToken = $vendorIntegration -> getRefreshToken(); $this -> accessToken = $vendorIntegration -> getAccessToken(); - $this -> expiresIn = $vendorIntegration -> getExpiresIn(); + $this -> accessExpiresIn = $vendorIntegration -> getExpiresIn(); $this -> description = $vendorIntegration->getZoomAccountDescription(); $zoomClient = new kZoomClient($this -> baseURL, $this -> jwtToken, $this -> refreshToken, $this -> clientId, - $this -> clientSecret, $this -> accessToken, $this -> expiresIn); + $this -> clientSecret, $this -> accessToken, $this -> accessExpiresIn); if ($this -> accessToken && $this -> refreshToken && kCurrentContext ::$ks_partner_id == Partner::BATCH_PARTNER_ID && $vendorIntegration -> getExpiresIn() <= time() + @@ -107,6 +107,7 @@ public function doFromObject($sourceObject, KalturaDetachedResponseProfile $resp { $this -> accessToken = $freshTokens[kZoomTokens::ACCESS_TOKEN]; $this -> refreshToken = $freshTokens[kZoomTokens::REFRESH_TOKEN]; + $this -> accessExpiresIn = $freshTokens[kZoomTokens::EXPIRES_IN]; $vendorIntegration -> saveTokensData($freshTokens); } } diff --git a/plugins/vendor/zoom/infra/kZoomClient.php b/plugins/vendor/zoom/infra/kZoomClient.php index 94a06fbf852..508107478b8 100644 --- a/plugins/vendor/zoom/infra/kZoomClient.php +++ b/plugins/vendor/zoom/infra/kZoomClient.php @@ -23,7 +23,7 @@ class kZoomClient protected $zoomBaseURL; protected $refreshToken; protected $accessToken; - protected $expiresIn; + protected $accessExpiresIn; protected $jwtToken; protected $clientId; protected $clientSecret; @@ -37,11 +37,11 @@ class kZoomClient * @param null $clientId * @param null $clientSecret * @param null $accessToken - * @param null $expiresIn + * @param null $accessExpiresIn * @throws KalturaAPIException */ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null, $clientId = null, - $clientSecret= null, $accessToken = null, $expiresIn = null) + $clientSecret= null, $accessToken = null, $accessExpiresIn = null) { $this -> zoomBaseURL = $zoomBaseURL; // check if at least one is available, otherwise throw exception @@ -54,7 +54,7 @@ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->accessToken = $accessToken; - $this->expiresIn = $expiresIn; + $this->accessExpiresIn = $accessExpiresIn; $this->zoomTokensHelper = new kZoomTokens($zoomBaseURL, $clientId, $clientSecret); } @@ -261,7 +261,7 @@ protected function generateContextualUrl($apiPath) $url = $this -> zoomBaseURL . $apiPath . '?'; if ($this->refreshToken) { - if (!$this->accessToken || ($this->expiresIn && $this->expiresIn <= time())) + if (!$this->accessToken || ($this->accessExpiresIn && $this->accessExpiresIn <= time())) { $this->refreshTokens(); } @@ -277,6 +277,7 @@ public function refreshTokens() $tokens = $this -> zoomTokensHelper -> refreshTokens($this -> refreshToken); $this -> accessToken = $tokens[kZoomTokens::ACCESS_TOKEN]; $this -> refreshToken = $tokens[kZoomTokens::REFRESH_TOKEN]; + $this -> accessExpiresIn = $tokens[kZoomTokens::EXPIRES_IN]; } return $tokens; diff --git a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php index 355d1149436..f2fe5207795 100644 --- a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php +++ b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php @@ -97,12 +97,12 @@ protected function initZoomClient(ZoomVendorIntegration $zoomVendorIntegration) $jwtToken = $zoomVendorIntegration->getJwtToken(); $refreshToken = $zoomVendorIntegration->getRefreshToken(); $accessToken = $zoomVendorIntegration->getAccessToken(); - $expiresIn = $zoomVendorIntegration->getExpiresIn(); + $accessExpiresIn = $zoomVendorIntegration->getExpiresIn(); $zoomConfiguration = kConf::get(self::CONFIGURATION_PARAM_NAME, self::MAP_NAME); $clientId = $zoomConfiguration['clientId']; $zoomBaseURL = $zoomConfiguration['ZoomBaseUrl']; $clientSecret = $zoomConfiguration['clientSecret']; - return new kZoomClient($zoomBaseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); + return new kZoomClient($zoomBaseURL, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn); } diff --git a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php index 1e0600ff2f1..cd9db8da8a1 100644 --- a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php +++ b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php @@ -26,11 +26,11 @@ abstract class kZoomProcessor * @param string $clientId * @param string $clientSecret * @param string $accessToken - * @param string $expiresIn + * @param string $accessExpiresIn */ - public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn) + public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn) { - $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $expiresIn); + $this->zoomClient = new kZoomClient($zoomBaseUrl, $jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn); } /** diff --git a/plugins/vendor/zoom/services/ZoomVendorService.php b/plugins/vendor/zoom/services/ZoomVendorService.php index 95949800c0d..6d91618cbb1 100644 --- a/plugins/vendor/zoom/services/ZoomVendorService.php +++ b/plugins/vendor/zoom/services/ZoomVendorService.php @@ -103,7 +103,8 @@ public function preOauthValidation() $authCode = $_GET[self::AUTH_CODE]; $tokens = kZoomOauth::requestAccessToken($authCode); $accessToken = $tokens[kZoomOauth::ACCESS_TOKEN]; - $client = new kZoomClient($zoomBaseURL, null, null, null, null, $accessToken, null); + $accessExpiresIn = $tokens[kZoomOauth::EXPIRES_IN]; + $client = new kZoomClient($zoomBaseURL, null, null, null, null, $accessToken, $accessExpiresIn); $permissions = $client->retrieveTokenZoomUserPermissions(); $user = $client->retrieveTokenZoomUser(); $accountId = $user[ZoomHelper::ACCOUNT_ID]; @@ -184,7 +185,7 @@ public function fetchRegistrationPageAction($tokensData, $iv) $zoomConfiguration = self::getZoomConfiguration(); $tokens = $this->handleEncryptTokens($tokensData, $iv, $zoomConfiguration); $zoomBaseURL = $zoomConfiguration[kZoomClient::ZOOM_BASE_URL]; - $client = new kZoomClient($zoomBaseURL,null,$tokens[kZoomTokens::REFRESH_TOKEN],null,null,$tokens[kZoomTokens::ACCESS_TOKEN], null); + $client = new kZoomClient($zoomBaseURL,null,$tokens[kZoomTokens::REFRESH_TOKEN],null,null,$tokens[kZoomTokens::ACCESS_TOKEN], $tokens[kZoomTokens::EXPIRES_IN]); $accountId = $this->getAccountId($client->retrieveTokenZoomUser()); $zoomIntegration = ZoomHelper::getZoomIntegrationByAccountId($accountId, true); $partnerId = kCurrentContext::getCurrentPartnerId(); @@ -216,7 +217,7 @@ public function localRegistrationPageAction($jwt) } $zoomConfiguration = self::getZoomConfiguration(); $zoomBaseURL = $zoomConfiguration[kZoomClient::ZOOM_BASE_URL]; - $client = new kZoomClient($zoomBaseURL,$jwt,null,null,null,null, null); + $client = new kZoomClient($zoomBaseURL, $jwt, null, null, null, null, null); $zoomAccountId = $this->getAccountId($client->retrieveTokenZoomUser()); $zoomIntegration = ZoomHelper::getZoomIntegrationByAccountId($zoomAccountId); if(!$zoomIntegration) From 2a350fb548c3ca906a2d40c4e98eda85acdd8434 Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Tue, 21 Dec 2021 13:05:41 +0200 Subject: [PATCH 4/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- plugins/vendor/zoom/lib/model/kZoomEventHanlder.php | 2 +- plugins/vendor/zoom/services/ZoomVendorService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php index f2fe5207795..d0129dfca37 100644 --- a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php +++ b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php @@ -85,7 +85,7 @@ public function processEvent($event) $transcriptProcessor = new kZoomTranscriptProcessor($this->zoomConfiguration[kZoomClient::ZOOM_BASE_URL], $zoomVendorIntegration->getJwtToken(), $zoomVendorIntegration->getRefreshToken(), - null, null, $zoomVendorIntegration->getAccessToken(),$zoomVendorIntegration->getExpiresIn()); + null, null, $zoomVendorIntegration->getAccessToken(), $zoomVendorIntegration->getExpiresIn()); $transcriptProcessor->handleRecordingTranscriptComplete($event); } break; diff --git a/plugins/vendor/zoom/services/ZoomVendorService.php b/plugins/vendor/zoom/services/ZoomVendorService.php index 6d91618cbb1..254812d2991 100644 --- a/plugins/vendor/zoom/services/ZoomVendorService.php +++ b/plugins/vendor/zoom/services/ZoomVendorService.php @@ -185,7 +185,7 @@ public function fetchRegistrationPageAction($tokensData, $iv) $zoomConfiguration = self::getZoomConfiguration(); $tokens = $this->handleEncryptTokens($tokensData, $iv, $zoomConfiguration); $zoomBaseURL = $zoomConfiguration[kZoomClient::ZOOM_BASE_URL]; - $client = new kZoomClient($zoomBaseURL,null,$tokens[kZoomTokens::REFRESH_TOKEN],null,null,$tokens[kZoomTokens::ACCESS_TOKEN], $tokens[kZoomTokens::EXPIRES_IN]); + $client = new kZoomClient($zoomBaseURL, null, $tokens[kZoomTokens::REFRESH_TOKEN], null, null, $tokens[kZoomTokens::ACCESS_TOKEN], $tokens[kZoomTokens::EXPIRES_IN]); $accountId = $this->getAccountId($client->retrieveTokenZoomUser()); $zoomIntegration = ZoomHelper::getZoomIntegrationByAccountId($accountId, true); $partnerId = kCurrentContext::getCurrentPartnerId(); From 0d7884b77d198a81df5abc6961512b23d47150bf Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Thu, 23 Dec 2021 13:14:11 +0200 Subject: [PATCH 5/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- .../ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php | 4 ++-- plugins/vendor/zoom/infra/kZoomClient.php | 4 ++-- plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php index 5dd9d4d8763..1aacba5407c 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php @@ -21,8 +21,8 @@ class KalturaZoomDropFolder extends KalturaDropFolder public $accessToken; /** - * @readonly - */ + * @readonly + */ public $accessExpiresIn; /** diff --git a/plugins/vendor/zoom/infra/kZoomClient.php b/plugins/vendor/zoom/infra/kZoomClient.php index 508107478b8..93db96acb22 100644 --- a/plugins/vendor/zoom/infra/kZoomClient.php +++ b/plugins/vendor/zoom/infra/kZoomClient.php @@ -36,8 +36,8 @@ class kZoomClient * @param null $refreshToken * @param null $clientId * @param null $clientSecret - * @param null $accessToken - * @param null $accessExpiresIn + * @param null $accessToken + * @param null $accessExpiresIn * @throws KalturaAPIException */ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null, $clientId = null, diff --git a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php index cd9db8da8a1..7173c3c0763 100644 --- a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php +++ b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php @@ -25,8 +25,8 @@ abstract class kZoomProcessor * @param string $refreshToken * @param string $clientId * @param string $clientSecret - * @param string $accessToken - * @param string $accessExpiresIn + * @param string $accessToken + * @param string $accessExpiresIn */ public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn) { From 474cc14174a6af0659a08ec5240fa873d1bfc00a Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Sun, 26 Dec 2021 00:31:20 +0200 Subject: [PATCH 6/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- .../ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php | 4 ++-- plugins/vendor/zoom/infra/kZoomClient.php | 4 ++-- plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php index 1aacba5407c..89f60088a8f 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/lib/api/KalturaZoomDropFolder.php @@ -21,8 +21,8 @@ class KalturaZoomDropFolder extends KalturaDropFolder public $accessToken; /** - * @readonly - */ + * @readonly + */ public $accessExpiresIn; /** diff --git a/plugins/vendor/zoom/infra/kZoomClient.php b/plugins/vendor/zoom/infra/kZoomClient.php index 93db96acb22..ce4d7b55cea 100644 --- a/plugins/vendor/zoom/infra/kZoomClient.php +++ b/plugins/vendor/zoom/infra/kZoomClient.php @@ -36,8 +36,8 @@ class kZoomClient * @param null $refreshToken * @param null $clientId * @param null $clientSecret - * @param null $accessToken - * @param null $accessExpiresIn + * @param null $accessToken + * @param null $accessExpiresIn * @throws KalturaAPIException */ public function __construct($zoomBaseURL, $jwtToken = null, $refreshToken = null, $clientId = null, diff --git a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php index 7173c3c0763..d1136a6cac9 100644 --- a/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php +++ b/plugins/vendor/zoom/lib/model/processors/kZoomProcessor.php @@ -25,8 +25,8 @@ abstract class kZoomProcessor * @param string $refreshToken * @param string $clientId * @param string $clientSecret - * @param string $accessToken - * @param string $accessExpiresIn + * @param string $accessToken + * @param string $accessExpiresIn */ public function __construct($zoomBaseUrl,$jwtToken, $refreshToken, $clientId, $clientSecret, $accessToken, $accessExpiresIn) { From 7a819f5c527f217aeedb752868c88a1690a21a00 Mon Sep 17 00:00:00 2001 From: Salma Nassar Date: Thu, 30 Dec 2021 12:00:59 +0200 Subject: [PATCH 7/7] SUP-30033 add token expiry to zoom integration to cache token expiration when calling zoom API --- plugins/vendor/zoom/infra/kZoomTokens.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/plugins/vendor/zoom/infra/kZoomTokens.php b/plugins/vendor/zoom/infra/kZoomTokens.php index 964593e2ff9..50cb01ed539 100644 --- a/plugins/vendor/zoom/infra/kZoomTokens.php +++ b/plugins/vendor/zoom/infra/kZoomTokens.php @@ -19,17 +19,7 @@ public function __construct($zoomBaseURL, $clientId, $clientSecret) $this->clientId = $clientId; $this->clientSecret = $clientSecret; } - - public function generateAccessToken($refreshToken) - { - KalturaLog::debug('Refreshing access token from token ' . $refreshToken); - $postFields = "grant_type=refresh_token&refresh_token=$refreshToken"; - $response = $this->curlRetrieveTokensData($postFields); - $tokensData = $this->parseTokensResponse($response); - KalturaLog::debug('New tokens response' . print_r($tokensData, true)); - return $tokensData[self::ACCESS_TOKEN]; - } - + public function refreshTokens($oldRefreshToken) { KalturaLog::info('Refreshing Zoom Tokens');