Humhub 1.15.0 + OO 3.0.0 JWT Error => Solution

Document Server version: 7.5.1.23
Connector version: 3.0.0
Attach logs if possible.

Since the last Humhub Update the JWT Version has changed, and they’ve changed header behavior in version 6.6.0 (2023-06-13).
So the Connector throws some errors like:

Error: Firebase\JWT\JWT::decode(): Argument #3 ($headers) cannot be passed by reference in /var/www/vhosts

I try to attache a diff file with all affected lines and necessary adjustments, but new user cant upload files:

diff -uNr onlyoffice_vorher/controllers/BackendController.php onlyoffice/controllers/BackendController.php
--- onlyoffice_vorher/controllers/BackendController.php	2023-11-14 22:04:28.020274860 +0100
+++ onlyoffice/controllers/BackendController.php	2023-11-11 22:48:37.000000000 +0100
@@ -21,6 +21,7 @@
 use \humhub\components\Module;
 use humhub\modules\file\libs\FileHelper;
 use \Firebase\JWT\JWT;
+use Firebase\JWT\Key;
 
 class BackendController extends Controller
 {
@@ -91,7 +92,7 @@
             }
 
             try {
-                $ds = JWT::decode($token, $this->module->getJwtSecret(), array('HS256'));
+                $ds = JWT::decode($token, new Key($this->module->getJwtSecret(), 'HS256'));
             } catch (\Exception $ex) {
                 throw new HttpException(403, 'Invalid JWT signature');
             }
@@ -116,7 +117,7 @@
             }
 
             try {
-                $ds = JWT::decode($token, $this->module->getJwtSecret(), array('HS256'));
+                $ds = JWT::decode($token, new Key($this->module->getJwtSecret(), 'HS256'));
             } catch (\Exception $ex) {
                 throw new HttpException(403, 'Invalid JWT signature');
             }
@@ -164,7 +165,7 @@
             }
 
             try {
-                $ds = JWT::decode($token, $this->module->getJwtSecret(), array('HS256'));
+                $ds = JWT::decode($token, new Key($this->module->getJwtSecret(), 'HS256'));
                 $data = isset($ds->payload) ? (array)$ds->payload : (array)$ds;
             } catch (\Exception $ex) {
                 throw new HttpException(403, 'Invalid JWT signature');
diff -uNr onlyoffice_vorher/Module.php onlyoffice/Module.php
--- onlyoffice_vorher/Module.php	2023-11-14 22:04:27.988275602 +0100
+++ onlyoffice/Module.php	2023-11-11 22:57:54.000000000 +0100
@@ -21,6 +21,7 @@
 use humhub\modules\file\libs\FileHelper;
 use humhub\libs\CURLHelper;
 use \Firebase\JWT\JWT;
+use Firebase\JWT\Key;
 
 /**
  * File Module
@@ -270,8 +271,8 @@
             $headers = [];
             $headers['Accept'] = 'application/json';
             if ($this->isJwtEnabled()) {
-                $data['token'] = JWT::encode($data, $this->getJwtSecret());
-                $headers[$this->getHeader()] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret());
+                $data['token'] = JWT::encode($data, $this->getJwtSecret(), 'HS256');
+                $headers[$this->getHeader()] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret(), 'HS256');
             }
 
             $options = array(
@@ -342,8 +343,8 @@
             $headers = [];
             $headers['Accept'] = 'application/json';
             if ($this->isJwtEnabled()) {
-                $data['token'] = JWT::encode($data, $this->getJwtSecret());
-                $headers[$this->getHeader()] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret());
+                $data['token'] = JWT::encode($data, $this->getJwtSecret(), 'HS256');
+                $headers[$this->getHeader()] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret(), 'HS256');
             }
 
             $options = [
@@ -396,7 +397,7 @@
             $data['isEmpty'] = true;
         }
 
-        return JWT::encode($data, Yii::$app->settings->get('secret'));
+        return JWT::encode($data, Yii::$app->settings->get('secret'), 'HS256');
     }
 
     /**
@@ -405,7 +406,7 @@
     public function readHash($hash)
     {
         try {
-            $data = JWT::decode($hash, Yii::$app->settings->get('secret'), array('HS256'));
+            $data = JWT::decode($hash, new Key(Yii::$app->settings->get('secret'), 'HS256'));
         } catch (\Exception $ex) {
             $error = 'Invalid hash ' . $ex->getMessage();
             Yii::error($error);
diff -uNr onlyoffice_vorher/widgets/EditorWidget.php onlyoffice/widgets/EditorWidget.php
--- onlyoffice_vorher/widgets/EditorWidget.php	2023-11-14 22:04:27.980275786 +0100
+++ onlyoffice/widgets/EditorWidget.php	2023-11-11 22:36:38.000000000 +0100
@@ -205,7 +205,7 @@
         }
 
         if ($module->isJwtEnabled()) {
-            $token = JWT::encode($config, $module->getJwtSecret());
+            $token = JWT::encode($config, $module->getJwtSecret(), 'HS256');
             $config['token'] = $token;
         }
 

Hi @dopaminble :handshake:

Connector version 3.0.0 does not support HumHub version 1.15.

Please use the new connector version 3.1.0 available at the following link:
https://marketplace.humhub.com/module/onlyoffice/downloads

Change Log

3.1.0

Changed

  • HumHub 1.15 compatibility
  • hide close button for share-modal
  • refresh file key after uploading new file version