feat(php-laravel): add jwt token lifetime from config

This commit is contained in:
sshakndr
2025-02-24 12:04:51 +07:00
committed by Sergey Linnik
parent b6613b5d21
commit ce4b905f06
7 changed files with 11 additions and 16 deletions

View File

@ -1,14 +1,5 @@
# Change Log
- php: jwt token lifetime from config
- ruby: jwt token lifetime from config
- python: jwt token lifetime from config
- java-spring: jwt token lifetime from config
- java: jwt token lifetime from config
- csharp-mvc: jwt token lifetime from config
- csharp: jwt token lifetime from config
- golang: jwt token lifetime from config
## 1.13.0
- nodejs: rename in wopi
- nodejs: using faviconUrl from WOPI discovery
@ -28,6 +19,7 @@
- php-laravel: show forgotten files on a seperate page
- php-laravel: fetch files
- php-laravel: integrate sdk
- jwt token lifetime from config
- onUserActionRequired
- support pages, numbers, key formats
- support hwp, hwpx formats

View File

@ -30,6 +30,7 @@ DOCUMENT_SERVER_JWT_HEADER=Authorization
DOCUMENT_SERVER_JWT_ALGORITHM=HS256
DOCUMENT_SERVER_JWT_USE_FOR_REQUEST=true
DOCUMENT_SERVER_JWT_SECRET=secret
DOCUMENT_SERVER_JWT_EXPIRATION=5
DOCUMENT_SERVER_CONVERSION_TIMEOUT=120000

View File

@ -94,7 +94,7 @@ class ReferenceController extends Controller
];
if ($settings->getSetting('jwt.enabled')) {
$data['token'] = $jwt->encode($data, $settings->getSetting('jwt.secret'));
$data['token'] = $jwt->jwtEncode($data, $settings->getSetting('jwt.secret'), $settings->getSetting('jwt.expiration'));
}
return response()->json($data);

View File

@ -220,13 +220,13 @@ class EditorController extends Controller
// check if the secret key to generate token exists
if ($this->settings->getSetting('jwt.enabled')) {
// encode config into the token
$config['token'] = $jwt->encode($config, $this->settings->getSetting('jwt.secret'));
$config['token'] = $jwt->jwtEncode($config, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
// encode the dataInsertImage object into the token
$dataInsertImage['token'] = $jwt->encode($dataInsertImage, $this->settings->getSetting('jwt.secret'));
$dataInsertImage['token'] = $jwt->jwtEncode($dataInsertImage, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
// encode the dataDocument object into the token
$dataDocument['token'] = $jwt->encode($dataDocument, $this->settings->getSetting('jwt.secret'));
$dataDocument['token'] = $jwt->jwtEncode($dataDocument, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
// encode the dataSpreadsheet object into the token
$dataSpreadsheet['token'] = $jwt->encode($dataSpreadsheet, $this->settings->getSetting('jwt.secret'));
$dataSpreadsheet['token'] = $jwt->jwtEncode($dataSpreadsheet, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
}
$historyLayout = '';

View File

@ -360,7 +360,7 @@ class FileController extends Controller
];
if ($this->settings->getSetting('jwt.enabled')) {
$config['token'] = $jwt->encode($config, $this->settings->getSetting('jwt.secret'));
$config['token'] = $jwt->jwtEncode($config, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
}
return response()

View File

@ -36,6 +36,7 @@ class SettingsManager extends OnlyOfficeSettingsManager
$conversionUrl = $privateServerUrl.'/'.env('DOCUMENT_SERVER_CONVERTER_PATH', 'convert');
$commandUrl = $privateServerUrl.'/'.env('DOCUMENT_SERVER_COMMAND_PATH', 'command');
$jwtSecret = env('DOCUMENT_SERVER_JWT_SECRET', 'secret');
$jwtExpiration = env('DOCUMENT_SERVER_JWT_EXPIRATION', 5);
$jwtUseForRequest = env('DOCUMENT_SERVER_JWT_USE_FOR_REQUEST', true);
$publicStorageUrl = rtrim(env('DOCUMENT_STORAGE_PUBLIC_URL', request()->schemeAndHttpHost()), '/');
$privateStorageUrl = rtrim(env('DOCUMENT_STORAGE_PRIVATE_URL', $publicStorageUrl), '/');
@ -54,6 +55,7 @@ class SettingsManager extends OnlyOfficeSettingsManager
'jwt' => [
'enabled' => $jwtSecret && $jwtUseForRequest,
'secret' => $jwtSecret,
'expiration' => $jwtExpiration,
'header' => env('DOCUMENT_SERVER_JWT_HEADER', 'Authorization'),
'use_for_request' => $jwtUseForRequest,
'algorithm' => env('DOCUMENT_SERVER_JWT_ALGORITHM', 'HS256'),

View File

@ -62,7 +62,7 @@ class FindDocumentHistoryQueryHandler
$item['url'] = FileURL::download(
PathInfo::basename($request->filename), $request->userAddress
);
$item['token'] = $this->jwt->encode($item, $this->settings->getSetting('jwt.secret'));
$item['token'] = $this->jwt->jwtEncode($item, $this->settings->getSetting('jwt.secret'), $this->settings->getSetting('jwt.expiration'));
$history['history'][] = $item;
}